public void thenApplyWithContext(Function<Result, Result> fn) { this.resultFuture = resultFuture.thenApply(fn.compose(beforeContext).andThen(afterContext)); }
public void thenApplyWithContext(Function<Result, Result> fn) { this.resultFuture = resultFuture.thenApply(fn.compose(beforeContext).andThen(afterContext)); }
public static void main(String[] args) { InputLambda15 ex = new InputLambda15(); Function<Double, Double> sin = d -> ex.sin(d); Function<Double, Double> log = d -> ex.log(d); Function<Double, Double> exp = d -> ex.exp(d); InputLambda15 compose = new InputLambda15(); LOG.info(compose.calculate(sin.compose(log), 0.8).toString()); // prints log:sin:-0.22 LOG.info(compose.calculate(sin.andThen(log), 0.8).toString()); // prints sin:log:-0.33 LOG.info(compose.calculate(sin.compose(log).andThen(exp), 0.8).toString()); //log:sin:exp:0.80 LOG.info(compose.calculate(sin.compose(log).compose(exp), 0.8).toString()); //exp:log:sin:0.71 LOG.info(compose.calculate(sin.andThen(log).compose(exp), 0.8).toString()); //exp:sin:log:-0.23 LOG.info(compose.calculate(sin.andThen(log).andThen(exp), 0.8).toString()); //sin:log:exp:0.71 }
/** * Generate an infinite Stream that iterates from the specified seed using the currently wrapped function * * e.g. * * <pre> * {@code * FluentFunctions.of(this::addOne) .iterate(95281,i->i) .forEach(System.out::println); * * * //95282 //95283 //95284 //95285 //95286 * //etc * } * </pre> * * * @param seed initial value * @param mapToType Convert from supplied function return type to Stream input type * @return Infinite Stream */ public ReactiveSeq<R> iterate(final T seed, final Function<R, T> mapToType) { return ReactiveSeq.iterate(fn.apply(seed), t -> fn.compose(mapToType) .apply(t)); }
@Override public <EX extends Throwable> ReactiveSeq<T> recover(final Class<EX> exceptionClass, final Function<? super EX, ? extends T> fn) { Function<? super Throwable, ? extends EX> accept = e -> { if (exceptionClass.isAssignableFrom(e.getClass())) { return (EX) e; } throw ExceptionSoftener.throwSoftenedException(e); }; return createSeq(new RecoverOperator<>(source, fn.compose(accept))); }
@Override public <T, R> App<PStore.Mu<I, J>, R> map(final Function<? super T, ? extends R> func, final App<PStore.Mu<I, J>, T> ts) { final PStore<I, J, T> input = PStore.unbox(ts); return Optics.pStore(func.compose(input::peek)::apply, input::pos); } }
@Override public <T, R2> App<ReaderMu<R>, R2> map(final Function<? super T, ? extends R2> func, final App<ReaderMu<R>, T> ts) { return FunctionType.create(func.compose(FunctionType.unbox(ts))); }
@Override public <P extends K2> Function<App2<P, A1, B1>, App2<P, S, T>> eval(final App<? extends Proof, P> proof) { return outer.eval(proof).compose(inner.eval(proof)); }
public static <T2,T,R> StreamFlatMappingSpliterator<T2,R> compose(FunctionSpliterator<T2,T> fnS,Function<? super T, ? extends Stream<? extends R>> mapper){ Function<? super T2,? extends T> fn = fnS.function(); return new StreamFlatMappingSpliterator<T2,R>(CopyableSpliterator.copy(fnS.source()),mapper.<T2>compose(fn)); } @Override
private <A, B, C> App2<FunctionType.Mu, A, B> cap(final Procompose<FunctionType.Mu, FunctionType.Mu, A, B, C> cmp) { return create(Optics.getFunc(cmp.second()).compose(Optics.getFunc(cmp.first().get()))); }
public static <T2,T,R> IterableFlatMappingSpliterator<T2,R> compose(FunctionSpliterator<T2,T> fnS,Function<? super T, ? extends Iterable<? extends R>> mapper){ Function<? super T2,? extends T> fn = fnS.function(); return new IterableFlatMappingSpliterator<T2,R>(CopyableSpliterator.copy(fnS.source()),mapper.<T2>compose(fn)); } @Override
public static <T2,T,R> PublisherFlatMappingSpliterator<T2,R> compose(FunctionSpliterator<T2,T> fnS,Function<? super T, ? extends Publisher<? extends R>> mapper){ Function<? super T2,? extends T> fn = fnS.function(); return new PublisherFlatMappingSpliterator<T2,R>(CopyableSpliterator.copy(fnS.source()),mapper.<T2>compose(fn)); } @Override
@Property public <V> void defaultMethods( Function<? super V, ? extends Date> first, Function<? super Date, Integer> second, V arg) { Date intermediate = first.apply(arg); Integer ultimate = second.apply(intermediate); assertEquals(ultimate, second.compose(first).apply(arg)); assertEquals(ultimate, first.andThen(second).apply(arg)); } }
private Maybe<String> testComposition(Functor<?, F> functor) { Functor<Integer, F> subject = functor.fmap(constantly(1)); Function<Integer, Integer> f = x -> x * 3; Function<Integer, Integer> g = x -> x - 2; return subject.fmap(f.compose(g)).equals(subject.fmap(g).fmap(f)) ? nothing() : just("composition (functor.fmap(f.compose(g)).equals(functor.fmap(g).fmap(f)))"); } }
private Maybe<String> testNaturality(Traversable<?, Trav> trav) { Function<Object, Identity<Object>> f = Identity::new; Function<Identity<Object>, Either<String, Object>> t = id -> right(id.runIdentity()); Function<Traversable<Object, Trav>, Applicative<Traversable<Object, Trav>, Identity>> pureFn = x -> new Identity<>(x); Function<Traversable<Object, Trav>, Applicative<Traversable<Object, Trav>, Either<String, ?>>> pureFn2 = x -> right(x); return t.apply(trav.traverse(f, pureFn).<Object>fmap(id()).coerce()) .equals(trav.traverse(t.compose(f), pureFn2).<Object>fmap(id()).coerce()) ? nothing() : just("naturality (t.apply(trav.traverse(f, pureFn).<Object>fmap(id()).coerce())\n" + " .equals(trav.traverse(t.compose(f), pureFn2).<Object>fmap(id()).coerce()))"); }
public final APIConnectionAsyncResponseComposer composeOnStatusReceived(final Function<HttpResponseStatus, AsyncHandler.State> before) { composeOnStatusReceive = composeOnStatusReceive.compose(httpStatus -> new StatusPart(httpStatus.getStatus(), isNull(before) ? State.CONTINUE : before.apply(httpStatus.getStatus()))); return this; }
public final APIConnectionAsyncResponseComposer composeOnHeadersReceived(final Function<HttpResponseHeaders, AsyncHandler.State> before) { composeOnHeadersReceive = composeOnHeadersReceive.compose(httpHeaders -> new HeadersPart(httpHeaders.getHeaders(), isNull(before) ? State.CONTINUE : before.apply(httpHeaders.getHeaders()))); return this; }
public static <T2,T,R> StreamFlatMappingSpliterator<T2,R> compose(FunctionSpliterator<T2,T> fnS,Function<? super T, ? extends Stream<? extends R>> mapper){ Function<? super T2,? extends T> fn = fnS.function(); return new StreamFlatMappingSpliterator<T2,R>(CopyableSpliterator.copy(fnS.source()),mapper.<T2>compose(fn)); } @Override