java.util.function.Function.compose()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(8.3k)|赞(0)|评价(0)|浏览(342)

本文整理了Java中java.util.function.Function.compose()方法的一些代码示例,展示了Function.compose()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Function.compose()方法的具体详情如下:
包路径:java.util.function.Function
类名称:Function
方法名:compose

Function.compose介绍

[英]Returns a composed function that first applies the beforefunction to its input, and then applies this function to the result. If evaluation of either function throws an exception, it is relayed to the caller of the composed function.
[中]返回一个组合函数,该函数首先将beforefunction应用于其输入,然后将此函数应用于结果。如果对任一函数的求值引发异常,则会将其转发给组合函数的调用方。

代码示例

代码示例来源:origin: apache/incubator-dubbo

public void thenApplyWithContext(Function<Result, Result> fn) {
  this.resultFuture = resultFuture.thenApply(fn.compose(beforeContext).andThen(afterContext));
}

代码示例来源:origin: apache/incubator-dubbo

public void thenApplyWithContext(Function<Result, Result> fn) {
  this.resultFuture = resultFuture.thenApply(fn.compose(beforeContext).andThen(afterContext));
}

代码示例来源:origin: checkstyle/checkstyle

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
}

代码示例来源:origin: Mojang/DataFixerUpper

@Override
public <A, B, C, D> FunctionType<App2<FunctionType.Mu, A, B>, App2<FunctionType.Mu, C, D>> dimap(final Function<C, A> g, final Function<B, D> h) {
  return f -> create(h.compose(Optics.getFunc(f)).compose(g));
}

代码示例来源:origin: aol/cyclops

/**
 * 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));
}

代码示例来源:origin: aol/cyclops

@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)));
}

代码示例来源:origin: Mojang/DataFixerUpper

@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);
  }
}

代码示例来源:origin: Mojang/DataFixerUpper

@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)));
}

代码示例来源:origin: Mojang/DataFixerUpper

@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));
}

代码示例来源:origin: aol/cyclops

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

代码示例来源:origin: Mojang/DataFixerUpper

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())));
}

代码示例来源:origin: aol/cyclops

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

代码示例来源:origin: aol/cyclops

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

代码示例来源:origin: pholser/junit-quickcheck

@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));
  }
}

代码示例来源:origin: palatable/lambda

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)))");
  }
}

代码示例来源:origin: com.diffplug.durian/durian-collect

/** Decorates errors thrown by assertions with the given function. */
@Override
public SameType<T> decorateErrorsWith(Function<? super T, String> toString) {
  comparison.decorateErrorsWith(toString.compose(mapExpected), toString.compose(mapActual));
  return this;
}

代码示例来源:origin: palatable/lambda

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()))");
}

代码示例来源:origin: com.tomitribe.tribestream/tribestream-container

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;
}

代码示例来源:origin: com.tomitribe.tribestream/tribestream-container

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;
}

代码示例来源:origin: com.oath.cyclops/cyclops

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

相关文章