public static class FluentFunctions.FluentBiFunction<T1,T2,R> extends java.lang.Object implements Fn2<T1,T2,R>
Fn2.FunctionalOperations<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 toNested 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 toNested 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 toNested this BiFunction
|
ReactiveSeq<R> |
generate(T1 input1,
T2 input2)
Generate an infinite Stream by applying the input parameters toNested 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<T1,T2,java.util.concurrent.CompletableFuture<R>> |
liftAsync(java.util.concurrent.Executor ex) |
FluentFunctions.FluentBiFunction<java.util.Optional<T1>,java.util.Optional<T2>,java.util.Optional<R>> |
liftOptional() |
<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 toNested 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 toNested 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 toNested this BiFunction toNested generate a Function (single input value)
|
FluentFunctions.FluentSupplier<R> |
partiallyApply(T1 param1,
T2 param2)
Partially apply the provided parameters toNested this BiFunction toNested 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 toNested the eventConsumer, if there is an error it will be passed toNested the errorConsumer
|
public FluentFunctions.FluentBiFunction<T1,T2,R> before(java.util.function.BiConsumer<T1,T2> action)
action
- BiConsumer toNested recieve input parameters toNested BiFunctionpublic FluentFunctions.FluentBiFunction<T1,T2,R> after(C3<T1,T2,R> action)
action
- C3 toNested 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 toNested be contolled via it's input parameterpublic FluentFunctions.FluentFunction<T2,R> partiallyApply(T1 param)
param
- Input parameter toNested Partially Appliedpublic FluentFunctions.FluentSupplier<R> partiallyApply(T1 param1, T2 param2)
param1
- First Input parameterparam2
- Second Input parameterpublic 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));
public 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 toNested recieve result on successful executionerrorConsumer
- Consumer toNested 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 toNested 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 <X extends java.lang.Throwable> FluentFunctions.FluentBiFunction<T1,T2,Try<R,X>> liftTry(java.lang.Class<X>... classes)
classes
- Classes toNested catch exceptions forpublic FluentFunctions.FluentBiFunction<java.util.Optional<T1>,java.util.Optional<T2>,java.util.Optional<R>> liftOptional()
public FluentFunctions.FluentBiFunction<T1,T2,java.util.concurrent.CompletableFuture<R>> liftAsync(java.util.concurrent.Executor ex)
ex
- Executor toNested 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 toNested execute this BiFunction on