@Override public <R> Future<R> concatMap(final Function<? super T, ? extends Iterable<? extends R>> mapper) { return (Future<R>) MonadicValue.super.concatMap(mapper); }
@Override default Maybe<T> filterNot(final Predicate<? super T> fn) { return (Maybe<T>) MonadicValue.super.filterNot(fn); }
/** * Perform a two level nested internal iteration over this MonadicValue and the * supplied MonadicValue * * <pre> * {@code * Maybe.of(3) * .forEach2(a->Maybe.none(), * (a,b)->a+b); * * * //Maybe.none() * } * </pre> * * * @param value1 * Nested Monadic Type to iterate over * @param yieldingFunction * Function with pointers to the current element from both * monad types that generates the new elements * @return MonadicValue with elements generated via nested iteration */ default <R1, R> MonadicValue<R> forEach2(Function<? super T, ? extends MonadicValue<R1>> value1, final BiFunction<? super T, ? super R1, ? extends R> yieldingFunction){ return this.flatMap(in-> { MonadicValue<R1> b = value1.apply(in); return b.map(in2->yieldingFunction.apply(in, in2)); }); }
/** * A flattening transformation operation that takes the first value from the returned Publisher. * <pre> * {@code * Future.ofResult(1).map(i->i+2).mergeMap(i->Flux.just(()->i*3,20); * //Future[9] * * }</pre> * * @param mapper transformation function * @return MonadicValue */ default <R> MonadicValue<R> mergeMap(final Function<? super T, ? extends Publisher<? extends R>> mapper) { return this.flatMap(a -> { final Publisher<? extends R> publisher = mapper.apply(a); final ValueSubscriber<R> sub = ValueSubscriber.subscriber(); publisher.subscribe(sub); final Maybe<R> maybe = sub.toMaybe(); return maybe.fold(in->unit(in),__->emptyUnit()); }); }
@Override default <T2, R1, R2, R> Eval<R> forEach3(Function<? super T, ? extends MonadicValue<R1>> value1, BiFunction<? super T, ? super R1, ? extends MonadicValue<R2>> value2, Function3<? super T, ? super R1, ? super R2, Boolean> filterFunction, Function3<? super T, ? super R1, ? super R2, ? extends R> yieldingFunction) { return (Eval<R>)MonadicValue.super.forEach3(value1, value2, filterFunction, yieldingFunction); }
@Override default <R1, R> Option<R> forEach2(Function<? super T, ? extends MonadicValue<R1>> value1, BiFunction<? super T, ? super R1, ? extends R> yieldingFunction) { return (Option<R>)MonadicValue.super.forEach2(value1, yieldingFunction); }
@Override default <T2, R1, R2, R3, R> Eval<R> forEach4(Function<? super T, ? extends MonadicValue<R1>> value1, BiFunction<? super T, ? super R1, ? extends MonadicValue<R2>> value2, Function3<? super T, ? super R1, ? super R2, ? extends MonadicValue<R3>> value3, Function4<? super T, ? super R1, ? super R2, ? super R3, Boolean> filterFunction, Function4<? super T, ? super R1, ? super R2, ? super R3, ? extends R> yieldingFunction) { return (Eval<R>)MonadicValue.super.forEach4(value1, value2, value3, filterFunction, yieldingFunction); }
private <PT> LazyEither<ST, PT> toEither(MonadicValue<? extends PT> value) { return value.fold(p -> LazyEither.right(p), () -> LazyEither.left(null)); }
/** * A flattening transformation operation that takes the first value from the returned Iterable. * * <pre> * {@code * Maybe.just(1).map(i->i+2).concatMap(i->Arrays.asList(()->i*3,20); * //Maybe[9] * * }</pre> * * * @param mapper transformation function * @return MonadicValue */ default <R> MonadicValue<R> concatMap(final Function<? super T, ? extends Iterable<? extends R>> mapper) { return this.flatMap(a -> { return Maybe.fromIterable(mapper.apply(a)); }); }
final BiFunction<? super T, ? super R1, ? extends MonadicValue<R2>> value2, final Function3<? super T, ? super R1, ? super R2, ? extends R> yieldingFunction){ return this.flatMap(in-> { return a.flatMap(ina-> { MonadicValue<R2> b = value2.apply(in,ina); return b.map(in2->yieldingFunction.apply(in,ina, in2)); });
/** * A flattening transformation operation that takes the first value from the returned Publisher. * <pre> * {@code * Future.ofResult(1).map(i->i+2).mergeMap(i->Flux.just(()->i*3,20); * //Future[9] * * }</pre> * * @param mapper transformation function * @return MonadicValue */ default <R> MonadicValue<R> mergeMap(final Function<? super T, ? extends Publisher<? extends R>> mapper) { return this.flatMap(a -> { final Publisher<? extends R> publisher = mapper.apply(a); final ValueSubscriber<R> sub = ValueSubscriber.subscriber(); publisher.subscribe(sub); final Maybe<R> maybe = sub.toMaybe(); return maybe.fold(in->unit(in),__->emptyUnit()); }); }
@Override default <T2, R1, R2, R> Eval<R> forEach3(Function<? super T, ? extends MonadicValue<R1>> value1, BiFunction<? super T, ? super R1, ? extends MonadicValue<R2>> value2, Function3<? super T, ? super R1, ? super R2, ? extends R> yieldingFunction) { return (Eval<R>)MonadicValue.super.forEach3(value1, value2, yieldingFunction); }
@Override default <R1, R> Option<R> forEach2(Function<? super T, ? extends MonadicValue<R1>> value1, BiFunction<? super T, ? super R1, Boolean> filterFunction, BiFunction<? super T, ? super R1, ? extends R> yieldingFunction) { return (Option<R>)MonadicValue.super.forEach2(value1, filterFunction, yieldingFunction); }
@Override default <T2, R1, R2, R3, R> Option<R> forEach4(Function<? super T, ? extends MonadicValue<R1>> value1, BiFunction<? super T, ? super R1, ? extends MonadicValue<R2>> value2, Function3<? super T, ? super R1, ? super R2, ? extends MonadicValue<R3>> value3, Function4<? super T, ? super R1, ? super R2, ? super R3, ? extends R> yieldingFunction) { return (Option<R>)MonadicValue.super.forEach4(value1, value2, value3, yieldingFunction); }