ST
- Secondary typePT
- Primary typepublic interface Ior<ST,PT> extends To<Ior<ST,PT>>, java.util.function.Supplier<PT>, MonadicValue<PT>, BiFunctor<ST,PT>, Functor<PT>, Filterable<PT>, ApplicativeFunctor<PT>
Modifier and Type | Interface and Description |
---|---|
static class |
Ior.Both<ST,PT> |
static class |
Ior.Primary<ST,PT> |
static class |
Ior.Secondary<ST,PT> |
ApplicativeFunctor.Applicatives, ApplicativeFunctor.ApplyFunctions<T>
Value.ValueImpl<T>
Convertable.SupplierToConvertable<T>
Modifier and Type | Method and Description |
---|---|
static <ST,PT,R> Ior<?,R> |
accumulatePrimary(CollectionX<Ior<ST,PT>> iors,
java.util.function.Function<? super PT,R> mapper,
Semigroup<R> reducer)
Accumulate the results only from those Iors which have a Primary type present, using the supplied mapping function to
convert the data from each Ior before reducing them using the supplied Semgigroup (a combining BiFunction/BinaryOperator that takes two
input values of the same type and returns the combined result)
Semigroups . |
static <ST,PT,R> Ior<?,R> |
accumulatePrimary(CollectionX<Ior<ST,PT>> iors,
Reducer<R> reducer)
Accumulate the result of the Primary types in the Collection of Iors provided using the supplied Reducer
Reducers . |
static <ST,PT> Ior<?,PT> |
accumulatePrimary(CollectionX<Ior<ST,PT>> iors,
Semigroup<PT> reducer)
Accumulate the results only from those Iors which have a Primary type present, using the supplied Semgigroup (a combining BiFunction/BinaryOperator that takes two
input values of the same type and returns the combined result)
Semigroups . |
static <ST,PT,R> Ior<?,R> |
accumulateSecondary(CollectionX<Ior<ST,PT>> iors,
java.util.function.Function<? super ST,R> mapper,
Monoid<R> reducer)
Accumulate the results only from those Iors which have a Secondary type present, using the supplied mapping function to
convert the data from each Ior before reducing them using the supplied Monoid (a combining BiFunction/BinaryOperator and identity element that takes two
input values of the same type and returns the combined result)
Monoids . |
static <ST,PT,R> Ior<?,R> |
accumulateSecondary(CollectionX<Ior<ST,PT>> iors,
Reducer<R> reducer)
Accumulate the result of the Secondary types in the Collection of Iors provided using the supplied Reducer
Reducers . |
static <ST,PT> Ior<?,ST> |
accumulateSecondary(Monoid<ST> reducer,
CollectionX<Ior<ST,PT>> iors)
Accumulate the results only from those Iors which have a Secondary type present, using the supplied Monoid (a combining BiFunction/BinaryOperator and identity element that takes two
input values of the same type and returns the combined result)
Monoids . |
default AnyMValue<PT> |
anyM() |
default <U1,U2> Ior<U1,U2> |
bicast(java.lang.Class<U1> type1,
java.lang.Class<U2> type2)
Cast two data types simulatanously.
|
default <R1,R2> Ior<R1,R2> |
bimap(java.util.function.Function<? super ST,? extends R1> fn1,
java.util.function.Function<? super PT,? extends R2> fn2)
Transform this BiFunctor, changing two value types at once.
|
default Ior<ST,PT> |
bipeek(java.util.function.Consumer<? super ST> c1,
java.util.function.Consumer<? super PT> c2)
Peek at two data types simulatanously (typically to perform a side-effect with each data point)
|
default <R1,R2> Ior<R1,R2> |
bitrampoline(java.util.function.Function<? super ST,? extends Trampoline<? extends R1>> mapper1,
java.util.function.Function<? super PT,? extends Trampoline<? extends R2>> mapper2)
Perform a tail-call optimized recursive transformation operation across two data points simultaneously
|
java.util.Optional<org.jooq.lambda.tuple.Tuple2<ST,PT>> |
both() |
static <ST,PT> Ior<ST,PT> |
both(Ior<ST,PT> secondary,
Ior<ST,PT> primary)
Deprecated.
|
static <ST,PT> Ior<ST,PT> |
both(ST secondary,
PT primary)
Create an Ior instance that contains both secondary and primary types
|
default Value<java.util.Optional<org.jooq.lambda.tuple.Tuple2<ST,PT>>> |
bothValue() |
default <U> Ior<ST,U> |
cast(java.lang.Class<? extends U> type)
Cast all elements in a stream to a given type, possibly throwing a
ClassCastException . |
default <R> Ior<ST,R> |
coflatMap(java.util.function.Function<? super MonadicValue<PT>,R> mapper)
Perform a coflatMap operation.
|
default Ior<ST,PT> |
combine(java.util.function.BinaryOperator<Combiner<PT>> combiner,
Combiner<PT> app)
Combine two applicatives together using the provided BinaryOperator (Semigroup, Monoid and Reducer all
extend BinaryOperator - checkout Semigroups and Monoids for a large number of canned combinations).
|
default <T2,R> Ior<ST,R> |
combine(Value<? extends T2> app,
java.util.function.BiFunction<? super PT,? super T2,? extends R> fn)
Lazily combine this ApplicativeFunctor with the supplied value via the supplied BiFunction
Example
|
default Ior<ST,PT> |
combineEager(Monoid<PT> monoid,
MonadicValue<? extends PT> v2)
Eagerly combine two MonadicValues using the supplied monoid (@see ApplicativeFunctor for type appropraite i.e.
|
Ior<ST,PT> |
filter(java.util.function.Predicate<? super PT> test)
Keep only elements for which the supplied predicates hold
e.g.
|
default Ior<ST,PT> |
filterNot(java.util.function.Predicate<? super PT> fn)
Remove any elements for which the predicate holds (inverse operation to filter)
e.g.
|
<RT1> Ior<ST,RT1> |
flatMap(java.util.function.Function<? super PT,? extends MonadicValue<? extends RT1>> mapper)
A flattening transformation operation (@see
Optional.flatMap(Function) |
default <R> Ior<ST,R> |
flatMapIterable(java.util.function.Function<? super PT,? extends java.lang.Iterable<? extends R>> mapper)
A flattening transformation operation that takes the first value from the returned Iterable.
|
default <R> Ior<ST,R> |
flatMapPublisher(java.util.function.Function<? super PT,? extends org.reactivestreams.Publisher<? extends R>> mapper)
A flattening transformation operation that takes the first value from the returned Publisher.
|
default <R1,R> Ior<ST,R> |
forEach2(java.util.function.Function<? super PT,? extends MonadicValue<R1>> value1,
java.util.function.BiFunction<? super PT,? super R1,? extends R> yieldingFunction)
Perform a two level nested internal iteration over this MonadicValue and the
supplied MonadicValue
|
default <R1,R> Ior<ST,R> |
forEach2(java.util.function.Function<? super PT,? extends MonadicValue<R1>> value1,
java.util.function.BiFunction<? super PT,? super R1,java.lang.Boolean> filterFunction,
java.util.function.BiFunction<? super PT,? super R1,? extends R> yieldingFunction)
Perform a two level nested internal iteration over this MonadicValue and the
supplied stream
|
default <T2,R1,R2,R> |
forEach3(java.util.function.Function<? super PT,? extends MonadicValue<R1>> value1,
java.util.function.BiFunction<? super PT,? super R1,? extends MonadicValue<R2>> value2,
TriFunction<? super PT,? super R1,? super R2,? extends R> yieldingFunction)
Perform a three level nested internal iteration over this MonadicValue and the
supplied MonadicValues
|
default <T2,R1,R2,R> |
forEach3(java.util.function.Function<? super PT,? extends MonadicValue<R1>> value1,
java.util.function.BiFunction<? super PT,? super R1,? extends MonadicValue<R2>> value2,
TriFunction<? super PT,? super R1,? super R2,java.lang.Boolean> filterFunction,
TriFunction<? super PT,? super R1,? super R2,? extends R> yieldingFunction)
Perform a three level nested internal iteration over this MonadicValue and the
supplied MonadicValues
|
default <T2,R1,R2,R3,R> |
forEach4(java.util.function.Function<? super PT,? extends MonadicValue<R1>> value1,
java.util.function.BiFunction<? super PT,? super R1,? extends MonadicValue<R2>> value2,
TriFunction<? super PT,? super R1,? super R2,? extends MonadicValue<R3>> value3,
QuadFunction<? super PT,? super R1,? super R2,? super R3,? extends R> yieldingFunction)
Perform a four level nested internal iteration over this MonadicValue and the
supplied MonadicValues
|
default <T2,R1,R2,R3,R> |
forEach4(java.util.function.Function<? super PT,? extends MonadicValue<R1>> value1,
java.util.function.BiFunction<? super PT,? super R1,? extends MonadicValue<R2>> value2,
TriFunction<? super PT,? super R1,? super R2,? extends MonadicValue<R3>> value3,
QuadFunction<? super PT,? super R1,? super R2,? super R3,java.lang.Boolean> filterFunction,
QuadFunction<? super PT,? super R1,? super R2,? super R3,? extends R> yieldingFunction)
Perform a four level nested internal iteration over this MonadicValue and the
supplied MonadicValues
Maybe.of(3)
.forEach4(a->Maybe.just(a+10),
(a,b)->Maybe.just(a+b),
(a,b,c)->Maybe.none(),
(a,b,c,d)->a+b+c<100,
(a,b,c,d)->a+b+c+d);
//Maybe.none
|
static <ST,T> Ior<ST,T> |
fromIterable(java.lang.Iterable<T> iterable)
Construct an Ior that contains a single value extracted from the supplied Iterable
|
static <T> Ior<java.lang.Throwable,T> |
fromPublisher(org.reactivestreams.Publisher<T> pub)
Construct an Ior that contains a single value extracted from the supplied reactive-streams Publisher
|
PT |
get() |
boolean |
isBoth() |
default boolean |
isPresent() |
boolean |
isPrimary() |
boolean |
isSecondary() |
<R> Ior<ST,R> |
map(java.util.function.Function<? super PT,? extends R> fn)
Transform this functor using the supplied transformation function
|
<R> Eval<R> |
matches(java.util.function.Function<Matchable.CheckValue1<ST,R>,Matchable.CheckValue1<ST,R>> secondary,
java.util.function.Function<Matchable.CheckValue1<PT,R>,Matchable.CheckValue1<PT,R>> primary,
java.util.function.Function<Matchable.CheckValue2<ST,PT,R>,Matchable.CheckValue2<ST,PT,R>> both,
java.util.function.Supplier<? extends R> otherwise)
Pattern match on the value/s inside this Ior.
|
default Ior<ST,MonadicValue<PT>> |
nest()
cojoin pattern.
|
default Ior<ST,PT> |
notNull()
Filter elements retaining only values which are not null
|
default <U> Ior<ST,U> |
ofType(java.lang.Class<? extends U> type)
Keep only those elements in a stream that are of a given type.
|
default <R> Xor<ST,R> |
patternMatch(java.util.function.Function<Matchable.CheckValue1<PT,R>,Matchable.CheckValue1<PT,R>> case1,
java.util.function.Supplier<? extends R> otherwise)
Transform the elements of this Stream with a Pattern Matching case and default value
|
Ior<ST,PT> |
peek(java.util.function.Consumer<? super PT> action)
Peek at the current value of this Functor, without transforming it
|
static <ST,PT> Ior<ST,PT> |
primary(PT primary)
Create an instance of the primary type.
|
static <ST,PT> Ior<ST,PT> |
secondary(ST secondary)
Create an instance of the secondary type.
|
<LT1> Ior<LT1,PT> |
secondaryFlatMap(java.util.function.Function<? super ST,? extends Ior<LT1,PT>> mapper)
Perform a flatMap operation on the Secondary type
|
ST |
secondaryGet() |
<R> Ior<R,PT> |
secondaryMap(java.util.function.Function<? super ST,? extends R> fn)
Always map the Secondary type of this Ior if it is present using the provided transformation function
|
Ior<ST,PT> |
secondaryPeek(java.util.function.Consumer<? super ST> action)
Peek at the Secondary type value if present
|
java.util.Optional<ST> |
secondaryToOptional() |
Ior<ST,PT> |
secondaryToPrimayFlatMap(java.util.function.Function<? super ST,? extends Ior<ST,PT>> fn)
A flatMap operation that keeps the Secondary and Primary types the same
|
Ior<ST,PT> |
secondaryToPrimayMap(java.util.function.Function<? super ST,? extends PT> fn)
If this Ior contains the Secondary type only, map it's value so that it contains the Primary type only
If this Ior contains both types, this method has no effect in the default implementations
|
ReactiveSeq<ST> |
secondaryToStream() |
Value<ST> |
secondaryValue() |
static <ST,PT> Ior<ListX<ST>,ListX<PT>> |
sequencePrimary(CollectionX<Ior<ST,PT>> iors)
Turn a collection of Iors into a single Ior with Lists of values.
|
static <ST,PT> Ior<ListX<PT>,ListX<ST>> |
sequenceSecondary(CollectionX<Ior<ST,PT>> iors)
Turn a collection of Iors into a single Ior with Lists of values.
|
Ior<PT,ST> |
swap() |
default Ior<ST,PT> |
toIor()
Return an Ior that can be this object or a Ior.primary or Ior.secondary
|
Xor<ST,PT> |
toXor() |
default <ST2> Xor<ST2,PT> |
toXor(ST2 secondary)
Convert to an Xor where the secondary value will be used if no primary value is present
|
Xor<ST,PT> |
toXorDropPrimary() |
default <R> Ior<ST,R> |
trampoline(java.util.function.Function<? super PT,? extends Trampoline<? extends R>> mapper)
Performs a map operation that can call a recursive method without running out of stack space
|
default <T> Ior<ST,T> |
unit(T unit) |
default <R> R |
visit(java.util.function.Function<? super ST,? extends R> secondary,
java.util.function.Function<? super PT,? extends R> primary,
java.util.function.BiFunction<? super ST,? super PT,? extends R> both)
Visitor pattern for this Ior.
|
default <T2,R> Ior<ST,R> |
zip(java.util.function.BiFunction<? super PT,? super T2,? extends R> fn,
org.reactivestreams.Publisher<? extends T2> app)
Zip (combine) this Zippable with the supplied Publisher, using the supplied combining function
|
default <T2,R> Ior<ST,R> |
zip(java.lang.Iterable<? extends T2> app,
java.util.function.BiFunction<? super PT,? super T2,? extends R> fn)
Zip (combine) this Zippable with the supplied Iterable using the supplied combining function
|
default <U> Ior<ST,org.jooq.lambda.tuple.Tuple2<PT,U>> |
zip(java.lang.Iterable<? extends U> other)
Zip (combine) this Zippable with the supplied Iterable combining both into a Tuple2
|
default <U> Ior<ST,org.jooq.lambda.tuple.Tuple2<PT,U>> |
zip(org.jooq.lambda.Seq<? extends U> other)
Zip (combine) this Zippable with the supplied Seq combining both into a Tuple2
|
default <U,R> Ior<ST,R> |
zip(org.jooq.lambda.Seq<? extends U> other,
java.util.function.BiFunction<? super PT,? super U,? extends R> zipper)
Zip (combine) this Zippable with the supplied Seq, using the supplied combining function
|
default <U> Ior<ST,org.jooq.lambda.tuple.Tuple2<PT,U>> |
zip(java.util.stream.Stream<? extends U> other)
Zip (combine) this Zippable with the supplied Stream combining both into a Tuple2
|
default <U,R> Ior<ST,R> |
zip(java.util.stream.Stream<? extends U> other,
java.util.function.BiFunction<? super PT,? super U,? extends R> zipper)
Zip (combine) this Zippable with the supplied Stream, using the supplied combining function
|
applyFunctions
collect, fold, fold, generate, iterate, iterator, mapReduce, mkString, newSubscriber, of, stream, subscribe, test, toDequeX, toEvalAlways, toEvalLater, toEvalNow, toFeatureToggle, toFutureStream, toFutureStream, toLazyImmutable, toList, toListX, toMaybe, toMutable, toPBagX, toPOrderedSetX, toPQueueX, toPSetX, toPStackX, toPVectorX, toQueueX, toSetX, toSimpleReact, toSimpleReact, toSortedSetX, toTry, toTry, toTry, unapply
endsWith, endsWithIterable, findAny, findFirst, firstValue, foldable, foldRight, foldRight, foldRight, foldRightMapToType, get, groupBy, join, join, join, mapReduce, print, print, printErr, printOut, reduce, reduce, reduce, reduce, reduce, reduce, reduce, schedule, scheduleFixedDelay, scheduleFixedRate, single, single, singleOptional, startsWith, startsWithIterable, toConcurrentLazyCollection, toConcurrentLazyStreamable, toLazyCollection, validate, xMatch
collect, fromSupplier, orElse, orElseGet, orElseThrow, toAtomicReference, toCompletableFuture, toCompletableFutureAsync, toCompletableFutureAsync, toFutureW, toFutureWAsync, toFutureWAsync, toOptional, toOptionalAtomicReference, toStream, visit
@Deprecated static <ST,PT> Ior<ST,PT> both(Ior<ST,PT> secondary, Ior<ST,PT> primary)
static <T> Ior<java.lang.Throwable,T> fromPublisher(org.reactivestreams.Publisher<T> pub)
ReactiveSeq<Integer> stream = ReactiveSeq.of(1,2,3);
Ior<Throwable,Integer> future = Ior.fromPublisher(stream);
//Ior[1]
pub
- Publisher to extract value fromstatic <ST,T> Ior<ST,T> fromIterable(java.lang.Iterable<T> iterable)
List<Integer> list = Arrays.asList(1,2,3);
Ior<Throwable,Integer> future = Ior.fromPublisher(list);
//Ior[1]
iterable
- Iterable to extract value fromstatic <ST,PT> Ior<ST,PT> primary(PT primary)
Ior.<Integer,Integer>primary(10).map(i->i+1);
//Ior.primary[11]
value
- To construct an Ior fromstatic <ST,PT> Ior<ST,PT> secondary(ST secondary)
Ior.<Integer,Integer>secondary(10).map(i->i+1);
//Ior.secondary[10]
Ior.<Integer,Integer>secondary(10).swap().map(i->i+1);
//Ior.primary[11]
value
- to wrapstatic <ST,PT> Ior<ST,PT> both(ST secondary, PT primary)
Ior<String,Ingeger> kv = Ior.both("hello",90);
//Ior["hello",90]
secondary
- Secondary valueprimary
- Primary valuedefault <T2,R1,R2,R3,R> Ior<ST,R> forEach4(java.util.function.Function<? super PT,? extends MonadicValue<R1>> value1, java.util.function.BiFunction<? super PT,? super R1,? extends MonadicValue<R2>> value2, TriFunction<? super PT,? super R1,? super R2,? extends MonadicValue<R3>> value3, QuadFunction<? super PT,? super R1,? super R2,? super R3,? extends R> yieldingFunction)
MonadicValue
Maybe.of(3)
.forEach4(a->Maybe.just(a+10),
(a,b)->Maybe.just(a+b),
(a,b,c)->Maybe.none(),
(a,b,c,d)->a+b+c+d);
//Maybe.none
forEach4
in interface MonadicValue<PT>
value1
- Nested MonadicValue to iterate overvalue2
- Nested MonadicValue to iterate overvalue3
- Nested MonadicValue to iterate overyieldingFunction
- Function with pointers to the current element from both
MonadicValue that generates the new elementsdefault <T2,R1,R2,R3,R> Ior<ST,R> forEach4(java.util.function.Function<? super PT,? extends MonadicValue<R1>> value1, java.util.function.BiFunction<? super PT,? super R1,? extends MonadicValue<R2>> value2, TriFunction<? super PT,? super R1,? super R2,? extends MonadicValue<R3>> value3, QuadFunction<? super PT,? super R1,? super R2,? super R3,java.lang.Boolean> filterFunction, QuadFunction<? super PT,? super R1,? super R2,? super R3,? extends R> yieldingFunction)
MonadicValue
Maybe.of(3)
.forEach4(a->Maybe.just(a+10),
(a,b)->Maybe.just(a+b),
(a,b,c)->Maybe.none(),
(a,b,c,d)->a+b+c<100,
(a,b,c,d)->a+b+c+d);
//Maybe.none
forEach4
in interface MonadicValue<PT>
value1
- Nested MonadicValue to iterate overvalue2
- Nested MonadicValue to iterate overvalue3
- Nested MonadicValue to iterate overfilterFunction
- Filter to apply over elements before passing non-filtered
values to the yielding functionyieldingFunction
- Function with pointers to the current element from both
MonadicValue that generates the new elementsdefault <T2,R1,R2,R> Ior<ST,R> forEach3(java.util.function.Function<? super PT,? extends MonadicValue<R1>> value1, java.util.function.BiFunction<? super PT,? super R1,? extends MonadicValue<R2>> value2, TriFunction<? super PT,? super R1,? super R2,? extends R> yieldingFunction)
MonadicValue
Maybe.of(3)
.forEach3(a->Maybe.just(a+10),
(a,b)->Maybe.just(a+b),
(a,b,c)->a+b+c<100,
(a,b,c)->a+b+c);
//Maybe[32]
forEach3
in interface MonadicValue<PT>
value1
- Nested MonadicValue to iterate overvalue2
- Nested MonadicValue to iterate overyieldingFunction
- Function with pointers to the current element from both
MonadicValue that generates the new elementsdefault <T2,R1,R2,R> Ior<ST,R> forEach3(java.util.function.Function<? super PT,? extends MonadicValue<R1>> value1, java.util.function.BiFunction<? super PT,? super R1,? extends MonadicValue<R2>> value2, TriFunction<? super PT,? super R1,? super R2,java.lang.Boolean> filterFunction, TriFunction<? super PT,? super R1,? super R2,? extends R> yieldingFunction)
MonadicValue
Maybe.of(3)
.forEach3(a->Maybe.just(a+10),
(a,b)->Maybe.just(a+b),
(a,b,c)->a+b+c<100,
(a,b,c)->a+b+c);
//Maybe[32]
forEach3
in interface MonadicValue<PT>
value1
- Nested MonadicValue to iterate overvalue2
- Nested MonadicValue to iterate overfilterFunction
- Filter to apply over elements before passing non-filtered
values to the yielding functionyieldingFunction
- Function with pointers to the current element from both
MonadicValue that generates the new elementsdefault <R1,R> Ior<ST,R> forEach2(java.util.function.Function<? super PT,? extends MonadicValue<R1>> value1, java.util.function.BiFunction<? super PT,? super R1,? extends R> yieldingFunction)
MonadicValue
Maybe.of(3)
.forEach2(a->Maybe.none(),
(a,b)->a+b);
//Maybe.none()
forEach2
in interface MonadicValue<PT>
value1
- Nested Monadic Type to iterate overyieldingFunction
- Function with pointers to the current element from both
monad types that generates the new elementsdefault <R1,R> Ior<ST,R> forEach2(java.util.function.Function<? super PT,? extends MonadicValue<R1>> value1, java.util.function.BiFunction<? super PT,? super R1,java.lang.Boolean> filterFunction, java.util.function.BiFunction<? super PT,? super R1,? extends R> yieldingFunction)
MonadicValue
Maybe.of(3)
.forEach2(a->Maybe.none(),
a->b-> a<3 && b>10,
(a,b)->a+b);
//Maybe.none()
forEach2
in interface MonadicValue<PT>
filterFunction
- Filter to apply over elements before passing non-filtered
values to the yielding functionyieldingFunction
- Function with pointers to the current element from both
Streams that generates the new elementsdefault <R> Ior<ST,R> flatMapIterable(java.util.function.Function<? super PT,? extends java.lang.Iterable<? extends R>> mapper)
MonadicValue
Maybe.just(1).map(i->i+2).flatMapIterable(i->Arrays.asList(()->i*3,20);
//Maybe[9]
flatMapIterable
in interface MonadicValue<PT>
mapper
- transformation functiondefault <R> Ior<ST,R> flatMapPublisher(java.util.function.Function<? super PT,? extends org.reactivestreams.Publisher<? extends R>> mapper)
MonadicValue
FutureW.ofResult(1).map(i->i+2).flatMapPublisher(i->Flux.just(()->i*3,20);
//FutureW[9]
flatMapPublisher
in interface MonadicValue<PT>
mapper
- transformation functiondefault AnyMValue<PT> anyM()
anyM
in interface MonadicValue<PT>
Ior<ST,PT> filter(java.util.function.Predicate<? super PT> test)
Filterable
of(1,2,3).filter(i->i>2);
//[3]
filter
in interface Filterable<PT>
filter
in interface MonadicValue<PT>
test
- to filter elements by, retaining matchesXor<ST,PT> toXorDropPrimary()
default <ST2> Xor<ST2,PT> toXor(ST2 secondary)
Value
default Ior<ST,PT> toIor()
Value
Ior<ST,PT> secondaryToPrimayMap(java.util.function.Function<? super ST,? extends PT> fn)
fn
- Function to map secondary type to primary<R> Ior<R,PT> secondaryMap(java.util.function.Function<? super ST,? extends R> fn)
fn
- Transformation function for Secondary types<R> Ior<ST,R> map(java.util.function.Function<? super PT,? extends R> fn)
Functor
of(1,2,3).map(i->i*2)
//[2,4,6]
map
in interface ConvertableFunctor<PT>
map
in interface Functor<PT>
map
in interface MonadicValue<PT>
fn
- Transformation functionIor<ST,PT> secondaryPeek(java.util.function.Consumer<? super ST> action)
action
- Consumer to peek at the Secondary type valueIor<ST,PT> peek(java.util.function.Consumer<? super PT> action)
Functor
of(1,2,3).map(System.out::println)
1
2
3
default <R> Ior<ST,R> coflatMap(java.util.function.Function<? super MonadicValue<PT>,R> mapper)
MonadicValue
Maybe.none().coflatMap(m -> m.isPresent() ? m.get() : 10);
//Maybe[10]
coflatMap
in interface MonadicValue<PT>
mapper
- Mapping / transformation functiondefault Ior<ST,MonadicValue<PT>> nest()
MonadicValue
nest
in interface MonadicValue<PT>
default Ior<ST,PT> combineEager(Monoid<PT> monoid, MonadicValue<? extends PT> v2)
MonadicValue
Monoid<Integer> add = Monoid.of(1,Semigroups.intSum);
Maybe.of(10).combineEager(add,Maybe.none());
//Maybe[10]
Maybe.none().combineEager(add,Maybe.of(10));
//Maybe[10]
Maybe.none().combineEager(add,Maybe.none());
//Maybe.none()
Maybe.of(10).combineEager(add,Maybe.of(10));
//Maybe[20]
Monoid<Integer> firstNonNull = Monoid.of(null , Semigroups.firstNonNull());
Maybe.of(10).combineEager(firstNonNull,Maybe.of(10));
//Maybe[10]
combineEager
in interface MonadicValue<PT>
java.util.Optional<org.jooq.lambda.tuple.Tuple2<ST,PT>> both()
default Value<java.util.Optional<org.jooq.lambda.tuple.Tuple2<ST,PT>>> bothValue()
default <R> Xor<ST,R> patternMatch(java.util.function.Function<Matchable.CheckValue1<PT,R>,Matchable.CheckValue1<PT,R>> case1, java.util.function.Supplier<? extends R> otherwise)
Functor
List<String> result = CollectionX.of(1,2,3,4)
.patternMatch(
c->c.valuesWhere(i->"even", (Integer i)->i%2==0 )
)
// CollectionX["odd","even","odd","even"]
patternMatch
in interface Functor<PT>
case1
- Function to generate a case (or chain of cases as a single case)otherwise
- Value if supplied case doesn't matchdefault <R1,R2> Ior<R1,R2> bimap(java.util.function.Function<? super ST,? extends R1> fn1, java.util.function.Function<? super PT,? extends R2> fn2)
BiFunctor
MapX<String,Integer> map = MapXs.of("hello",2);
MapX<String,Integer> transformedMap = map.bimap(s->s+" world",i->i*4);
//["hello world",8]
default <R> R visit(java.util.function.Function<? super ST,? extends R> secondary, java.util.function.Function<? super PT,? extends R> primary, java.util.function.BiFunction<? super ST,? super PT,? extends R> both)
Ior.primary(10)
.visit(secondary->"no", primary->"yes",(sec,pri)->"oops!")
//Ior["yes"]
Ior.secondary(90)
.visit(secondary->"no", primary->"yes",(sec,pri)->"oops!")
//Ior["no"]
Ior.both(10, "eek")
.visit(secondary->"no", primary->"yes",(sec,pri)->"oops!")
//Ior["oops!"]
secondary
- Function to execute if this is a Secondary Iorprimary
- Function to execute if this is a Primary Iorboth
- Function to execute if this Ior contains both types<R> Eval<R> matches(java.util.function.Function<Matchable.CheckValue1<ST,R>,Matchable.CheckValue1<ST,R>> secondary, java.util.function.Function<Matchable.CheckValue1<PT,R>,Matchable.CheckValue1<PT,R>> primary, java.util.function.Function<Matchable.CheckValue2<ST,PT,R>,Matchable.CheckValue2<ST,PT,R>> both, java.util.function.Supplier<? extends R> otherwise)
import static com.aol.cyclops.control.Matchable.otherwise;
import static com.aol.cyclops.control.Matchable.then;
import static com.aol.cyclops.control.Matchable.when;
import static com.aol.cyclops.util.function.Predicates.instanceOf;
Ior.primary(10)
.matches(c->c.is(when("10"),then("hello")),
c->c.is(when(instanceOf(Integer.class)), then("error")),
c->c.is(when("10",10), then("boo!")),
otherwise("miss"));
//Eval["error"]
secondary
- Pattern matching function executed if this Ior has the secondary type onlyprimary
- Pattern matching function executed if this Ior has the primary type onlyboth
- Pattern matching function executed if this Ior has both typesotherwise
- Supplier used to provide a value if the selecting pattern matching function fails to find a matchPT get()
get
in interface Convertable<PT>
get
in interface java.util.function.Supplier<PT>
default boolean isPresent()
isPresent
in interface Convertable<PT>
Value<ST> secondaryValue()
ST secondaryGet()
java.util.Optional<ST> secondaryToOptional()
ReactiveSeq<ST> secondaryToStream()
<RT1> Ior<ST,RT1> flatMap(java.util.function.Function<? super PT,? extends MonadicValue<? extends RT1>> mapper)
MonadicValue
Optional.flatMap(Function)
Eval.now(1).map(i->i+2).flatMap(i->Eval.later(()->i*3);
//Eval[9]
flatMap
in interface MonadicValue<PT>
mapper
- transformation function<LT1> Ior<LT1,PT> secondaryFlatMap(java.util.function.Function<? super ST,? extends Ior<LT1,PT>> mapper)
mapper
- Flattening transformation functionIor<ST,PT> secondaryToPrimayFlatMap(java.util.function.Function<? super ST,? extends Ior<ST,PT>> fn)
fn
- Transformation functionboolean isPrimary()
boolean isSecondary()
boolean isBoth()
static <ST,PT> Ior<ListX<PT>,ListX<ST>> sequenceSecondary(CollectionX<Ior<ST,PT>> iors)
Ior<String,Integer> just = Ior.primary(10);
Ior<String,Integer> none = Ior.secondary("none");
Ior<ListX<Integer>,ListX<String>> iors =Ior.sequenceSecondary(ListX.of(just,none,Ior.primary(1)));
//Ior.primary(ListX.of("none")))
iors
- Iors to sequencestatic <ST,PT,R> Ior<?,R> accumulateSecondary(CollectionX<Ior<ST,PT>> iors, Reducer<R> reducer)
Reducers
.
Ior<String,Integer> just = Ior.primary(10);
Ior<String,Integer> none = Ior.secondary("none");
Ior<?,PSetX<String>> iors = Ior.accumulateSecondary(ListX.of(just,none,Ior.primary(1)),Reducers.<String>toPSetX());
//Ior.primary(PSetX.of("none"))));
iors
- Collection of Iors to accumulate secondary valuesreducer
- Reducer to accumulate resultsstatic <ST,PT,R> Ior<?,R> accumulateSecondary(CollectionX<Ior<ST,PT>> iors, java.util.function.Function<? super ST,R> mapper, Monoid<R> reducer)
Monoids
.
Ior<String,Integer> just = Ior.primary(10);
Ior<String,Integer> none = Ior.secondary("none");
Ior<?,String> iors = Ior.accumulateSecondary(ListX.of(just,none,Ior.secondary("1")),i->""+i,Monoids.stringConcat);
//Ior.primary("none1")
iors
- Collection of Iors to accumulate secondary valuesmapper
- Mapping function to be applied to the result of each Iorreducer
- Semigroup to combine values from each Iorstatic <ST,PT> Ior<?,ST> accumulateSecondary(Monoid<ST> reducer, CollectionX<Ior<ST,PT>> iors)
Monoids
.
Ior<String,Integer> just = Ior.primary(10);
Ior<String,Integer> none = Ior.secondary("none");
Ior<?,Integer> iors = Ior.accumulateSecondary(Monoids.intSum,ListX.of(Ior.both(2, "boo!"),Ior.secondary(1)));
//Ior.primary(3); 2+1
iors
- Collection of Iors to accumulate secondary valuesreducer
- Semigroup to combine values from each Iorstatic <ST,PT> Ior<ListX<ST>,ListX<PT>> sequencePrimary(CollectionX<Ior<ST,PT>> iors)
Ior<String,Integer> just = Ior.primary(10);
Ior<String,Integer> none = Ior.secondary("none");
Ior<ListX<String>,ListX<Integer>> iors =Ior.sequencePrimary(ListX.of(just,none,Ior.primary(1)));
//Ior.primary(ListX.of(10,1)));
iors
- Iors to sequencestatic <ST,PT,R> Ior<?,R> accumulatePrimary(CollectionX<Ior<ST,PT>> iors, Reducer<R> reducer)
Reducers
.
Ior<String,Integer> just = Ior.primary(10);
Ior<String,Integer> none = Ior.secondary("none");
Ior<?,PSetX<Integer>> iors =Ior.accumulatePrimary(ListX.of(just,none,Ior.primary(1)),Reducers.toPSetX());
//Ior.primary(PSetX.of(10,1))));
iors
- Collection of Iors to accumulate primary valuesreducer
- Reducer to accumulate resultsstatic <ST,PT,R> Ior<?,R> accumulatePrimary(CollectionX<Ior<ST,PT>> iors, java.util.function.Function<? super PT,R> mapper, Semigroup<R> reducer)
Semigroups
.
Ior<String,Integer> just = Ior.primary(10);
Ior<String,Integer> none = Ior.secondary("none");
Ior<?,String> iors = Ior.accumulatePrimary(ListX.of(just,none,Ior.primary(1)),i->""+i,Semigroups.stringConcat);
//Ior.primary("101"));
iors
- Collection of Iors to accumulate primary valuesmapper
- Mapping function to be applied to the result of each Iorreducer
- Reducer to accumulate resultsstatic <ST,PT> Ior<?,PT> accumulatePrimary(CollectionX<Ior<ST,PT>> iors, Semigroup<PT> reducer)
Semigroups
.
Ior<String,Integer> just = Ior.primary(10);
Ior<String,Integer> none = Ior.secondary("none");
Ior<?,Integer> iors =Ior.accumulatePrimary(ListX.of(just,none,Ior.primary(1)),Semigroups.intSum);
//Ior.primary(11);
iors
- Collection of Iors to accumulate primary valuesreducer
- Reducer to accumulate resultsdefault <T2,R> Ior<ST,R> combine(Value<? extends T2> app, java.util.function.BiFunction<? super PT,? super T2,? extends R> fn)
Combiner
Maybe<Integer> some = Maybe.just(10);
just.combine(Eval.now(20), this::add);
//Some[30]
Maybe<Integer> none = Maybe.none();
none.combine(Eval.now(20), this::add);
//None
default Ior<ST,PT> combine(java.util.function.BinaryOperator<Combiner<PT>> combiner, Combiner<PT> app)
Combiner
combine
in interface Combiner<PT>
Semigroup
,
Semigroups
,
Monoid
,
To lift any Semigroup (or monoid) up to handling Applicatives use the combineApplicatives operator in Semigroups
{@see com.aol.cyclops.Semigroups#combineApplicatives(BiFunction) } or Monoids
{ {@see com.aol.cyclops.Monoids#combineApplicatives(java.util.function.Function, com.aol.cyclops.Monoid)
}
{@code
BinaryOperator> sumMaybes = Semigroups.combineScalarFunctors(Semigroups.intSum);
Maybe.just(1)
.combine(sumMaybes, Maybe.just(5))
//Maybe.just(6));
}
default <U> Ior<ST,U> ofType(java.lang.Class<? extends U> type)
Filterable
// (1, 2, 3) ReactiveSeq.of(1, "a", 2, "b",3).ofType(Integer.class)
ofType
in interface Filterable<PT>
default Ior<ST,PT> filterNot(java.util.function.Predicate<? super PT> fn)
Filterable
of(1,2,3).filter(i->i>2);
//[1,2]
filterNot
in interface Filterable<PT>
fn
- to filter elements by, retaining matchesdefault Ior<ST,PT> notNull()
Filterable
of(1,2,null,4).nonNull();
//[1,2,4]
notNull
in interface Filterable<PT>
default <U> Ior<ST,U> cast(java.lang.Class<? extends U> type)
Functor
ClassCastException
.
// ClassCastException ReactiveSeq.of(1, "a", 2, "b", 3).cast(Integer.class)default <R> Ior<ST,R> trampoline(java.util.function.Function<? super PT,? extends Trampoline<? extends R>> mapper)
Functor
ReactiveSeq.of(10,20,30,40)
.trampoline(i-> fibonacci(i))
.forEach(System.out::println);
Trampoline<Long> fibonacci(int i){
return fibonacci(i,1,0);
}
Trampoline<Long> fibonacci(int n, long a, long b) {
return n == 0 ? Trampoline.done(b) : Trampoline.more( ()->fibonacci(n-1, a+b, a));
}
55
6765
832040
102334155
ReactiveSeq.of(10_000,200_000,3_000_000,40_000_000)
.trampoline(i-> fibonacci(i))
.forEach(System.out::println);
completes successfully
trampoline
in interface Functor<PT>
mapper
- TCO Transformation functiondefault Ior<ST,PT> bipeek(java.util.function.Consumer<? super ST> c1, java.util.function.Consumer<? super PT> c2)
BiFunctor
MapX<String,Integer> map = MapXs.of("hello",2);
map.bipeek(s->System.out.pritnln("key = " + s),System.out::println);
default <U1,U2> Ior<U1,U2> bicast(java.lang.Class<U1> type1, java.lang.Class<U2> type2)
BiFunctor
MapX<Animal,Food> map = MapXs.of(cow,grass);
MapX<Mamaml,Vegitation> herbervoreMammals = map.bicast(Mammal.class,Vegitation.class);
default <R1,R2> Ior<R1,R2> bitrampoline(java.util.function.Function<? super ST,? extends Trampoline<? extends R1>> mapper1, java.util.function.Function<? super PT,? extends Trampoline<? extends R2>> mapper2)
BiFunctor
bitrampoline
in interface BiFunctor<ST,PT>
mapper1
- transformation function for the first typemapper2
- transformation function for the second typedefault <T2,R> Ior<ST,R> zip(java.lang.Iterable<? extends T2> app, java.util.function.BiFunction<? super PT,? super T2,? extends R> fn)
Zippable
default <T2,R> Ior<ST,R> zip(java.util.function.BiFunction<? super PT,? super T2,? extends R> fn, org.reactivestreams.Publisher<? extends T2> app)
Zippable
default <U,R> Ior<ST,R> zip(org.jooq.lambda.Seq<? extends U> other, java.util.function.BiFunction<? super PT,? super U,? extends R> zipper)
Zippable
default <U,R> Ior<ST,R> zip(java.util.stream.Stream<? extends U> other, java.util.function.BiFunction<? super PT,? super U,? extends R> zipper)
Zippable
default <U> Ior<ST,org.jooq.lambda.tuple.Tuple2<PT,U>> zip(java.util.stream.Stream<? extends U> other)
Zippable
default <U> Ior<ST,org.jooq.lambda.tuple.Tuple2<PT,U>> zip(org.jooq.lambda.Seq<? extends U> other)
Zippable