@Override public boolean hasNext() { return !complete[0] && fold(p->true,()->false); }
@Override public T next() { complete[0]=true; return fold(p->p,()->null); } };
default Option<T> toOption() { return fold(Option::some,Option::none); }
default boolean isPresent(){ return fold(p->true,()->false); }
default Optional<T> toOptional(){ return fold(Optional::of,Optional::empty); }
default T orElse(T alt) { return fold(p->p,()->alt); }
default void forEach(Consumer<? super T> c){ fold(p->{ c.accept(p); return null; },()->null); } /**
default T orElseGet(Supplier<? extends T> s) { return fold(p->p,()->s.get()); }
/** * Returns the class name and the name of the subclass, if there is any value, the value is showed between square brackets. * @return String */ default String mkString() { return fold(p->getClass().getSimpleName() + "[" + p + "]",()->getClass().getSimpleName() + "[]"); }
default NonEmptyList<T> nonEmptyList(T alt){ return NonEmptyList.of(fold(s->s,()->alt)); } default NonEmptyList<T> nonEmptyListGet(Supplier<T> alt){
/** * Convert to an Xor where the left value will be used if no right value is present * * @param secondary Value to use in case no right value is present * @return Right Either with same value as this Value, or a Left Either with the provided Value if this Value is zero */ default <ST> Either<ST, T> toEither(final ST secondary) { return fold(p-> Either.right(p),()-> Either.left(secondary)); } default LazyEither<Throwable, T> toLazyEither() {
@Override public T next() { complete[0]=true; return fold(p->p,()->null); } };
@Override public boolean hasNext() { return !complete[0] && fold(p->true,()->false); }
default Optional<T> toOptional(){ return fold(Optional::of,Optional::empty); }
default Option<T> toOption() { return fold(Option::some,Option::none); }
default void forEach(Consumer<? super T> c){ fold(p->{ c.accept(p); return null; },()->null); } /**
default T orElseGet(Supplier<? extends T> s) { return fold(p->p,()->s.get()); }
/** * Returns the class name and the name of the subclass, if there is any value, the value is showed between square brackets. * @return String */ default String mkString() { return fold(p->getClass().getSimpleName() + "[" + p + "]",()->getClass().getSimpleName() + "[]"); }
default NonEmptyList<T> nonEmptyList(T alt){ return NonEmptyList.of(fold(s->s,()->alt)); } default NonEmptyList<T> nonEmptyListGet(Supplier<T> alt){
/** * Convert to an Xor where the left value will be used if no right value is present * * @param secondary Value to use in case no right value is present * @return Right Either with same value as this Value, or a Left Either with the provided Value if this Value is zero */ default <ST> Either<ST, T> toEither(final ST secondary) { return fold(p-> Either.right(p),()-> Either.left(secondary)); } default LazyEither<Throwable, T> toLazyEither() {