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

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

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

import static com.github.tonivade.purefun.core.Precondition.checkNonNull;

import com.github.tonivade.purefun.Kind;

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

public final class Nil, T> implements PureStream {

  private final MonadDefer monad;

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

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

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

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

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

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

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

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

  @SuppressWarnings("unchecked")
  @Override
  public PureStream concat(PureStream other) {
    return (PureStream) other;
  }

  @Override
  public PureStream append(Kind other) {
    return new Cons<>(monad, Kind.narrowK(other), this);
  }

  @Override
  public PureStream prepend(Kind other) {
    return append(other);
  }

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

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

  @Override
  public  Kind foldRight(Kind begin,
      Function2, ? extends Kind> combinator) {
    return Kind.narrowK(begin);
  }

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

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

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

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

  @Override
  public  PureStream flatMap(Function1, ? extends R>> map) {
    return new Nil<>(monad);
  }

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

  @Override
  public PureStream intersperse(Kind value) {
    return this;
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy