public static class FluentFunctions.FluentBiFunction<T1,T2,R>
extends java.lang.Object
implements java.util.function.BiFunction<T1,T2,R>
Constructor and Description |
---|
FluentBiFunction(java.util.function.BiFunction<T1,T2,R> fn) |
Modifier and Type | Method and Description |
---|---|
FluentFunctions.FluentBiFunction<T1,T2,R> |
after(C3<T1,T2,R> action)
Apply after advice to this BiFunction
|
<V> FluentFunctions.FluentBiFunction<T1,T2,V> |
andThen(java.util.function.Function<? super R,? extends V> after) |
R |
apply(T1 t1,
T2 t2) |
FluentFunctions.FluentBiFunction<T1,T2,R> |
around(java.util.function.Function<FluentFunctions.Advice2<T1,T2,R>,R> around)
Apply around advice to this BiFunction
|
java.util.concurrent.CompletableFuture<FluentFunctions.FluentBiFunction<T1,T2,R>> |
async(java.util.concurrent.Executor ex)
Wrap this BiFunction in a CompletableFuture for asyncrhonous execution
|
FluentFunctions.FluentBiFunction<T1,T2,R> |
before(java.util.function.BiConsumer<T1,T2> action)
Apply before advice to this BiFunction
|
FluentFunctions.FluentFunction<T1,java.util.function.Function<T2,R>> |
curry()
Curry this BiFunction, that is convert it from a BiFunction that accepts two input parameters to a 'chain'
of two Functions that accept a single parameter
|
ReactiveSeq<R> |
generate(T1 input1,
T2 input2)
Generate an infinite Stream by applying the input parameters to this function
repeatedly
|
ReactiveSeq<R> |
iterate(T1 seed1,
T2 seed2,
java.util.function.Function<R,org.jooq.lambda.tuple.Tuple2<T1,T2>> mapToTypeAndSplit)
Generate an infinite Stream from the provided seed values and mapping function.
|
FluentFunctions.FluentBiFunction<java.util.Optional<T1>,java.util.Optional<T2>,java.util.Optional<R>> |
lift() |
FluentFunctions.FluentBiFunction<T1,T2,java.util.concurrent.CompletableFuture<R>> |
liftAsync(java.util.concurrent.Executor ex) |
<W extends WitnessType<W>> |
liftF() |
<X extends java.lang.Throwable> |
liftTry(java.lang.Class<X>... classes) |
FluentFunctions.FluentBiFunction<T1,T2,R> |
log(java.util.function.Consumer<java.lang.String> logger,
java.util.function.Consumer<java.lang.Throwable> error)
A BiFunction that logs it's success or error states to the provided Consumers
|
FluentFunctions.FluentBiFunction<T1,T2,R> |
memoize() |
FluentFunctions.FluentBiFunction<T1,T2,R> |
memoize(Cacheable<R> cache)
This methods creates a caching version of this BiFunction, caching is implemented via the Cacheable wrapper,
that can be used to wrap any concrete cache implementation
E.g.
|
FluentFunctions.FluentBiFunction<T1,T2,R> |
name(java.lang.String name) |
FluentFunctions.FluentFunction<T2,R> |
partiallyApply(T1 param)
Partially apply the provided parameter as the first parameter to this BiFunction to generate a Function (single input value)
|
FluentFunctions.FluentSupplier<R> |
partiallyApply(T1 param1,
T2 param2)
Partially apply the provided parameters to this BiFunction to generate a Supplier (that takes no inputs)
|
FluentFunctions.FluentBiFunction<T1,T2,R> |
println() |
<X extends java.lang.Throwable> |
recover(java.lang.Class<X> type,
java.util.function.BiFunction<T1,T2,R> onError)
A BiFunction that can recover from the specified exception types, using the provided recovery Function
|
FluentFunctions.FluentBiFunction<T1,T2,R> |
retry(int times,
int backoffStartTime)
A BiFunction capable of retrying on failure using an exponential backoff strategy
|
FluentFunctions.FluentBiFunction<T1,T2,R> |
visitEvent(java.util.function.Consumer<R> eventConsumer,
java.util.function.Consumer<java.lang.Throwable> errorConsumer)
Visit the result of this BiFunction once it has been executed, if the Function executes successfully the
result will be passes to the eventConsumer, if there is an error it will be passed to the errorConsumer
|
public FluentFunctions.FluentBiFunction<T1,T2,R> before(java.util.function.BiConsumer<T1,T2> action)
action
- BiConsumer to recieve input parameters to BiFunctionpublic FluentFunctions.FluentBiFunction<T1,T2,R> after(C3<T1,T2,R> action)
action
- C3 to recieve input parameters and return value from BiFunction after it has executedpublic FluentFunctions.FluentBiFunction<T1,T2,R> around(java.util.function.Function<FluentFunctions.Advice2<T1,T2,R>,R> around)
public int add(Integer a,Integer b ){
return a+b;
}
FluentFunctions.of(this::add)
.around(advice->advice.proceed1(advice.param1+1))
.println()
.apply(10,1)
//12 (input = 10+1 with advice + 1 = 12)
around
- Function that allows the execution of this BiFunction to be contolled via it's input parameterpublic FluentFunctions.FluentFunction<T2,R> partiallyApply(T1 param)
param
- Input parameter to Partially Appliedpublic FluentFunctions.FluentSupplier<R> partiallyApply(T1 param1, T2 param2)
param1
- First Input parameterparam2
- Second Input parameterpublic FluentFunctions.FluentFunction<T1,java.util.function.Function<T2,R>> curry()
public int add(Integer a,Integer b ){
return a+b;
}
FluentFunctions.of(this::add)
.curry()
.apply(1)
.apply(2);
//3
public FluentFunctions.FluentBiFunction<T1,T2,R> memoize()
public FluentFunctions.FluentBiFunction<T1,T2,R> memoize(Cacheable<R> cache)
Cache<Object, Integer> cache = CacheBuilder.newBuilder()
.maximumSize(1000)
.expireAfterWrite(10, TimeUnit.MINUTES)
.build();
called=0;
BiFunction<Integer,Integer,Integer> fn = FluentFunctions.of(this::add)
.name("myFunction")
.memoize((key,f)->cache.get(key,()->f.apply(key)));
fn.apply(10,1);
fn.apply(10,1);
fn.apply(10,1);
assertThat(called,equalTo(1));
cache
- Cache implementation wrapperpublic FluentFunctions.FluentBiFunction<T1,T2,R> name(java.lang.String name)
name
- To give this BiFunctionpublic FluentFunctions.FluentBiFunction<T1,T2,R> log(java.util.function.Consumer<java.lang.String> logger, java.util.function.Consumer<java.lang.Throwable> error)
logger
- Success loggererror
- Failure loggerpublic FluentFunctions.FluentBiFunction<T1,T2,R> visitEvent(java.util.function.Consumer<R> eventConsumer, java.util.function.Consumer<java.lang.Throwable> errorConsumer)
eventConsumer
- Consumer to recieve result on successful executionerrorConsumer
- Consumer to recieve error on failurepublic FluentFunctions.FluentBiFunction<T1,T2,R> println()
public <X extends java.lang.Throwable> FluentFunctions.FluentBiFunction<T1,T2,R> recover(java.lang.Class<X> type, java.util.function.BiFunction<T1,T2,R> onError)
type
- Recoverable exception typesonError
- Recovery BiFunctionpublic FluentFunctions.FluentBiFunction<T1,T2,R> retry(int times, int backoffStartTime)
times
- Number of times to retrybackoffStartTime
- Wait time before first retrypublic ReactiveSeq<R> iterate(T1 seed1, T2 seed2, java.util.function.Function<R,org.jooq.lambda.tuple.Tuple2<T1,T2>> mapToTypeAndSplit)
FluentFunctions.of(this::add)
.iterate(1,2,(i)->Tuple.tuple(i,i))
.limit(10)
.printOut();
//3
6
12
24
48
96
192
384
768
1536
seed1
- Initial input parameter 1seed2
- Initial input parameter 2mapToTypeAndSplit
- Reversed mapping functionpublic ReactiveSeq<R> generate(T1 input1, T2 input2)
input1
- First input parameterinput2
- Second input parameterpublic FluentFunctions.FluentBiFunction<java.util.Optional<T1>,java.util.Optional<T2>,java.util.Optional<R>> lift()
public <X extends java.lang.Throwable> FluentFunctions.FluentBiFunction<T1,T2,Try<R,X>> liftTry(java.lang.Class<X>... classes)
classes
- Classes to catch exceptions forpublic <W extends WitnessType<W>> FluentFunctions.FluentBiFunction<AnyM<W,T1>,AnyM<W,T2>,AnyM<W,R>> liftF()
public FluentFunctions.FluentBiFunction<T1,T2,java.util.concurrent.CompletableFuture<R>> liftAsync(java.util.concurrent.Executor ex)
ex
- Executor to execute this function onpublic java.util.concurrent.CompletableFuture<FluentFunctions.FluentBiFunction<T1,T2,R>> async(java.util.concurrent.Executor ex)
FluentFunctions.of(this::add)
.async(ex)
.thenApplyAsync(f->f.apply(4,1))
.join()
ex
- Executor to execute this BiFunction on