All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.tonivade.purefun.stream.Nil Maven / Gradle / Ivy

/*
 * Copyright (c) 2018-2020, Antonio Gabriel Muñoz Conejo 
 * Distributed under the terms of the MIT License
 */
package com.github.tonivade.purefun.stream;

import com.github.tonivade.purefun.Function1;
import com.github.tonivade.purefun.Function2;
import com.github.tonivade.purefun.Higher1;
import com.github.tonivade.purefun.Kind;
import com.github.tonivade.purefun.Matcher1;
import com.github.tonivade.purefun.PartialFunction1;
import com.github.tonivade.purefun.Tuple2;
import com.github.tonivade.purefun.type.Option;
import com.github.tonivade.purefun.typeclasses.MonadDefer;

import static java.util.Objects.requireNonNull;

final class Nil implements Stream {

  private final MonadDefer monad;

  Nil(MonadDefer monad) {
    this.monad = requireNonNull(monad);
  }

  @Override
  public Higher1> headOption() {
    return monad.pure(Option.none());
  }

  @Override
  public Higher1, Stream>>> split() {
    return monad.pure(Option.none());
  }

  @Override
  public Stream take(int n) {
    return this;
  }

  @Override
  public Stream drop(int n) {
    return this;
  }

  @Override
  public Stream filter(Matcher1 matcher) {
    return this;
  }

  @Override
  public Stream takeWhile(Matcher1 matcher) {
    return this;
  }

  @Override
  public Stream dropWhile(Matcher1 matcher) {
    return this;
  }

  @Override
  public Stream concat(Stream other) {
    return other;
  }

  @Override
  public Stream append(Higher1 other) {
    return new Cons<>(monad, other, this);
  }

  @Override
  public Stream prepend(Higher1 other) {
    return append(other);
  }

  @Override
  public  Stream collect(PartialFunction1 partial) {
    return new Nil<>(monad);
  }

  @Override
  public  Higher1 foldLeft(R begin, Function2 combinator) {
    return monad.pure(begin);
  }

  @Override
  public  Higher1 foldRight(Higher1 begin, Function2, Higher1> combinator) {
    return begin;
  }

  @Override
  public Higher1 exists(Matcher1 matcher) {
    return monad.pure(false);
  }

  @Override
  public Higher1 forall(Matcher1 matcher) {
    return monad.pure(true);
  }

  @Override
  public  Stream map(Function1 map) {
    return new Nil<>(monad);
  }

  @Override
  public  Stream mapEval(Function1> mapper) {
    return new Nil<>(monad);
  }

  @Override
  public  Stream flatMap(Function1> map) {
    return new Nil<>(monad);
  }

  @Override
  public Stream repeat() {
    return this;
  }

  @Override
  public Stream intersperse(Higher1 value) {
    return this;
  }

  @Override
  public StreamModule getModule() { throw new UnsupportedOperationException(); }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy