LT
- Left typeRT
- Right typepublic interface Ior<LT,RT> extends To<Ior<LT,RT>>, Value<RT>, OrElseValue<RT,Ior<LT,RT>>, Unit<RT>, Transformable<RT>, Filters<RT>, BiTransformable<LT,RT>, Higher2<DataWitness.ior,LT,RT>
Modifier and Type | Interface and Description |
---|---|
static class |
Ior.Both<ST,PT> |
static class |
Ior.Primary<ST,PT> |
static class |
Ior.Secondary<ST,PT> |
Modifier and Type | Method and Description |
---|---|
static <ST,PT,R> Ior<PT,R> |
accumulateLeft(java.lang.Iterable<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)
cyclops2.Monoids . |
static <ST,PT,R> Ior<PT,R> |
accumulateLeft(java.lang.Iterable<Ior<ST,PT>> iors,
Reducer<R,ST> reducer)
Accumulate the result of the Secondary types in the Collection of Iors provided using the supplied Reducer
cyclops2.Reducers . |
static <ST,PT> Ior<PT,ST> |
accumulateLeft(Monoid<ST> reducer,
java.lang.Iterable<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)
cyclops2.Monoids . |
static <ST,PT,R> Ior<ST,R> |
accumulateRight(java.lang.Iterable<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)
cyclops2.SemigroupK . |
static <ST,PT,R> Ior<ST,R> |
accumulateRight(java.lang.Iterable<Ior<ST,PT>> iors,
Reducer<R,PT> reducer)
Accumulate the result of the Primary types in the Collection of Iors provided using the supplied Reducer
cyclops2.Reducers . |
static <ST,PT> Ior<ST,PT> |
accumulateRight(java.lang.Iterable<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)
cyclops2.SemigroupK . |
static <X,LT extends X,M extends X,RT extends X,R> |
applyAny(Ior<LT,RT> either) |
default int |
arity() |
<R1,R2> Ior<R1,R2> |
bimap(java.util.function.Function<? super LT,? extends R1> fn1,
java.util.function.Function<? super RT,? extends R2> fn2)
Transform this BiTransformable, changing two value types at once.
|
default Ior<LT,RT> |
bipeek(java.util.function.Consumer<? super LT> c1,
java.util.function.Consumer<? super RT> c2)
Peek at two data types simulatanously (typically to perform a side-effect with each data point)
|
Option<Tuple2<LT,RT>> |
both() |
static <ST,PT> Ior<ST,PT> |
both(ST left,
PT right)
Create an Ior instance that contains both left and right types
|
default <R> Ior<LT,R> |
coflatMap(java.util.function.Function<? super Ior<LT,RT>,R> mapper) |
static <X,LT extends X,M extends X,RT extends X> |
consumeAny(Ior<LT,RT> either)
Static method useful as a method reference for fluent consumption of any value type stored in this Either
(will capture the lowest common type)
|
Option<RT> |
filter(java.util.function.Predicate<? super RT> test)
Keep only elements for which the supplied predicates hold
e.g.
|
default Option<RT> |
filterNot(java.util.function.Predicate<? super RT> fn)
Remove any elements for which the predicate holds (inverse operation to filter)
e.g.
|
<RT1> Ior<LT,RT1> |
flatMap(java.util.function.Function<? super RT,? extends Ior<? extends LT,? extends RT1>> mapper) |
<LT1> Ior<LT1,RT> |
flatMapLeft(java.util.function.Function<? super LT,? extends Ior<LT1,RT>> mapper)
Perform a flatMap operation on the Secondary type
|
<R> R |
fold(java.util.function.Function<? super LT,? extends R> secondary,
java.util.function.Function<? super RT,? extends R> primary,
java.util.function.BiFunction<? super LT,? super RT,? extends R> both)
Visitor pattern for this Ior.
|
default <R1,R> Ior<LT,R> |
forEach2(java.util.function.Function<? super RT,? extends Ior<LT,R1>> value1,
java.util.function.BiFunction<? super RT,? super R1,? extends R> yieldingFunction) |
default <T2,R1,R2,R> |
forEach3(java.util.function.Function<? super RT,? extends Ior<LT,R1>> value1,
java.util.function.BiFunction<? super RT,? super R1,? extends Ior<LT,R2>> value2,
Function3<? super RT,? super R1,? super R2,? extends R> yieldingFunction) |
default <T2,R1,R2,R3,R> |
forEach4(java.util.function.Function<? super RT,? extends Ior<LT,R1>> value1,
java.util.function.BiFunction<? super RT,? super R1,? extends Ior<LT,R2>> value2,
Function3<? super RT,? super R1,? super R2,? extends Ior<LT,R3>> value3,
Function4<? super RT,? super R1,? super R2,? super R3,? extends R> yieldingFunction) |
static <ST,T> Ior<ST,T> |
fromIterable(java.lang.Iterable<T> iterable,
T alt)
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
|
Option<RT> |
get() |
Option<LT> |
getLeft() |
boolean |
isBoth() |
boolean |
isLeft() |
default boolean |
isPresent() |
boolean |
isRight() |
static <LT,RT> Ior<LT,RT> |
left(LT left)
Create an instance of the left type.
|
<R> Ior<LT,R> |
map(java.util.function.Function<? super RT,? extends R> fn)
Transform this functor using the supplied transformation function
|
<R> Ior<R,RT> |
mapLeft(java.util.function.Function<? super LT,? extends R> fn) |
static <ST,T> Ior<ST,T> |
narrowK(Higher<Higher<DataWitness.ior,ST>,T> ior) |
static <ST,T> Ior<ST,T> |
narrowK2(Higher2<DataWitness.ior,ST,T> ior) |
default Ior<LT,Ior<LT,RT>> |
nest() |
default Option<RT> |
notNull()
Filter elements retaining only values which are not null
|
default <U> Option<U> |
ofType(java.lang.Class<? extends U> type)
Keep only those elements in a stream that are of a given type.
|
Ior<LT,RT> |
peek(java.util.function.Consumer<? super RT> action)
Peek at the current value of this Transformable, without transforming it
|
Ior<LT,RT> |
peekLeft(java.util.function.Consumer<? super LT> action) |
Ior<LT,RT> |
recover(RT value) |
Ior<LT,RT> |
recover(java.util.function.Supplier<? extends RT> value) |
Ior<LT,RT> |
recoverWith(java.util.function.Supplier<? extends Ior<LT,RT>> fn) |
static <LT,RT> Ior<LT,RT> |
right(RT right)
Create an instance of the right type.
|
static <L,T> Ior<L,ReactiveSeq<T>> |
sequence(ReactiveSeq<? extends Ior<L,T>> stream) |
static <ST,PT> Ior<PT,ReactiveSeq<ST>> |
sequenceLeft(java.lang.Iterable<? extends Ior<ST,PT>> iors)
Turn a toX of Iors into a single Ior with Lists of values.
|
static <ST,PT> Ior<ST,ReactiveSeq<PT>> |
sequenceRight(java.lang.Iterable<Ior<ST,PT>> iors)
Turn a toX of Iors into a single Ior with Lists of values.
|
Ior<RT,LT> |
swap() |
Either<LT,RT> |
toEither() |
default <ST2> Either<ST2,RT> |
toEither(ST2 secondary)
Convert to an Xor where the left value will be used if no right value is present
|
Either<LT,RT> |
toEitherDropRight() |
static <L,T,R> Ior<L,ReactiveSeq<R>> |
traverse(java.util.function.Function<? super T,? extends R> fn,
ReactiveSeq<Ior<L,T>> stream) |
default <T> Ior<LT,T> |
unit(T unit) |
static <X,LT extends X,RT extends X> |
visitAny(java.util.function.Consumer<? super X> c,
Ior<LT,RT> either) |
static <X,PT extends X,ST extends X,R> |
visitAny(Ior<ST,PT> either,
java.util.function.Function<? super X,? extends R> fn) |
static <L,T> Higher<Higher<DataWitness.ior,L>,T> |
widen(Ior<L,T> narrow) |
default <T2,R> Ior<LT,R> |
zip(Either<LT,? extends T2> app,
java.util.function.BiFunction<? super RT,? super T2,? extends R> fn) |
default <T2,R> Ior<LT,R> |
zip(Ior<LT,? extends T2> app,
java.util.function.BiFunction<? super RT,? super T2,? extends R> fn) |
orElseUse, orElseUse
asSupplier, collect, fold, forEach, generate, iterate, iterator, mkString, newSubscriber, nonEmptyList, nonEmptyListGet, orElse, orElseGet, print, print, printErr, printOut, stream, subscribe, toLazyEither, toLeft, toMaybe, toOption, toOptional, toRight, toTry, toTry, toTry, transform
static <L,T> Higher<Higher<DataWitness.ior,L>,T> widen(Ior<L,T> narrow)
default int arity()
static <X,LT extends X,M extends X,RT extends X> java.util.function.Consumer<java.util.function.Consumer<? super X>> consumeAny(Ior<LT,RT> either)
myEither.to(Xor::consumeAny)
.accept(System.out::println);
either
- Xor to consume value forstatic <X,LT extends X,M extends X,RT extends X,R> java.util.function.Function<java.util.function.Function<? super X,R>,R> applyAny(Ior<LT,RT> either)
static <X,PT extends X,ST extends X,R> R visitAny(Ior<ST,PT> either, java.util.function.Function<? super X,? extends R> fn)
static <X,LT extends X,RT extends X> X visitAny(java.util.function.Consumer<? super X> c, Ior<LT,RT> either)
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, T alt)
List<Integer> list = Arrays.asList(1,2,3);
Ior<Throwable,Integer> future = Ior.fromPublisher(list);
//Ior[1]
iterable
- Iterable to extract value fromstatic <LT,RT> Ior<LT,RT> right(RT right)
Ior.<Integer,Integer>right(10).map(i->i+1);
//Ior.right[11]
right
- To construct an Ior fromstatic <LT,RT> Ior<LT,RT> left(LT left)
Ior.<Integer,Integer>left(10).map(i->i+1);
//Ior.left[10]
Ior.<Integer,Integer>left(10).swap().map(i->i+1);
//Ior.right[11]
left
- to wrapstatic <ST,PT> Ior<ST,PT> both(ST left, PT right)
Ior<String,Ingeger> kv = Ior.both("hello",90);
//Ior["hello",90]
left
- Secondary valueright
- Primary valuedefault <T2,R1,R2,R3,R> Ior<LT,R> forEach4(java.util.function.Function<? super RT,? extends Ior<LT,R1>> value1, java.util.function.BiFunction<? super RT,? super R1,? extends Ior<LT,R2>> value2, Function3<? super RT,? super R1,? super R2,? extends Ior<LT,R3>> value3, Function4<? super RT,? super R1,? super R2,? super R3,? extends R> yieldingFunction)
default <T2,R1,R2,R> Ior<LT,R> forEach3(java.util.function.Function<? super RT,? extends Ior<LT,R1>> value1, java.util.function.BiFunction<? super RT,? super R1,? extends Ior<LT,R2>> value2, Function3<? super RT,? super R1,? super R2,? extends R> yieldingFunction)
default <R1,R> Ior<LT,R> forEach2(java.util.function.Function<? super RT,? extends Ior<LT,R1>> value1, java.util.function.BiFunction<? super RT,? super R1,? extends R> yieldingFunction)
Option<RT> filter(java.util.function.Predicate<? super RT> test)
Filters
of(1,2,3).filter(i->i>2);
//[3]
Either<LT,RT> toEitherDropRight()
default <ST2> Either<ST2,RT> toEither(ST2 secondary)
Value
<R> Ior<LT,R> map(java.util.function.Function<? super RT,? extends R> fn)
Transformable
of(1,2,3).map(i->i*2)
//[2,4,6]
map
in interface Transformable<RT>
fn
- Transformation functionIor<LT,RT> peek(java.util.function.Consumer<? super RT> action)
Transformable
of(1,2,3).map(System.out::println)
1
2
3
peek
in interface Transformable<RT>
action
- Consumer that recieves each element from this TransformableOption<Tuple2<LT,RT>> both()
<R1,R2> Ior<R1,R2> bimap(java.util.function.Function<? super LT,? extends R1> fn1, java.util.function.Function<? super RT,? extends R2> fn2)
BiTransformable
MapX<String,Integer> map = MapXs.of("hello",2);
MapX<String,Integer> transformedMap = map.bimap(s->s+" world",i->i*4);
//["hello world",8]
bimap
in interface BiTransformable<LT,RT>
fn1
- transformation function for the first typefn2
- transformation function for the second type<R> R fold(java.util.function.Function<? super LT,? extends R> secondary, java.util.function.Function<? super RT,? extends R> primary, java.util.function.BiFunction<? super LT,? super RT,? extends R> both)
Ior.right(10)
.visit(left->"no", right->"yes",(sec,pri)->"oops!")
//Ior["yes"]
Ior.left(90)
.visit(left->"no", right->"yes",(sec,pri)->"oops!")
//Ior["no"]
Ior.both(10, "eek")
.visit(left->"no", right->"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<RT1> Ior<LT,RT1> flatMap(java.util.function.Function<? super RT,? extends Ior<? extends LT,? extends RT1>> mapper)
<LT1> Ior<LT1,RT> flatMapLeft(java.util.function.Function<? super LT,? extends Ior<LT1,RT>> mapper)
mapper
- Flattening transformation functionboolean isRight()
boolean isLeft()
boolean isBoth()
static <ST,PT> Ior<PT,ReactiveSeq<ST>> sequenceLeft(java.lang.Iterable<? extends Ior<ST,PT>> iors)
Ior<String,Integer> just = Ior.right(10);
Ior<String,Integer> none = Ior.left("none");
Ior<Seq<Integer>,Seq<String>> iors =Ior.sequenceLeft(Seq.of(just,none,Ior.right(1)));
//Ior.right(Seq.of("none")))
iors
- Iors to sequencestatic <ST,PT,R> Ior<PT,R> accumulateLeft(java.lang.Iterable<Ior<ST,PT>> iors, Reducer<R,ST> reducer)
cyclops2.Reducers
.
Ior<String,Integer> just = Ior.right(10);
Ior<String,Integer> none = Ior.left("none");
Ior<?,PersistentSetX<String>> iors = Ior.accumulateLeft(Seq.of(just,none,Ior.right(1)),Reducers.<String>toPersistentSetX());
//Ior.right(PersistentSetX.of("none"))));
iors
- Collection of Iors to accumulate left valuesreducer
- Reducer to accumulate resultsstatic <ST,PT,R> Ior<PT,R> accumulateLeft(java.lang.Iterable<Ior<ST,PT>> iors, java.util.function.Function<? super ST,R> mapper, Monoid<R> reducer)
cyclops2.Monoids
.
Ior<String,Integer> just = Ior.right(10);
Ior<String,Integer> none = Ior.left("none");
Ior<?,String> iors = Ior.accumulateLeft(Seq.of(just,none,Ior.left("1")),i->""+i,Monoids.stringConcat);
//Ior.right("none1")
iors
- Collection of Iors to accumulate left valuesmapper
- Mapping function to be applied to the result of each Iorreducer
- Semigroup to combine values from each Iorstatic <ST,PT> Ior<PT,ST> accumulateLeft(Monoid<ST> reducer, java.lang.Iterable<Ior<ST,PT>> iors)
cyclops2.Monoids
.
Ior<String,Integer> just = Ior.right(10);
Ior<String,Integer> none = Ior.left("none");
Ior<?,Integer> iors = Ior.accumulateLeft(Monoids.intSum,Seq.of(Ior.both(2, "boo!"),Ior.left(1)));
//Ior.right(3); 2+1
iors
- Collection of Iors to accumulate left valuesreducer
- Semigroup to combine values from each Iorstatic <ST,PT> Ior<ST,ReactiveSeq<PT>> sequenceRight(java.lang.Iterable<Ior<ST,PT>> iors)
Ior<String,Integer> just = Ior.right(10);
Ior<String,Integer> none = Ior.left("none");
Ior<String,ReactiveSeq<Integer>> iors =Ior.sequenceRight(Seq.of(just,none,Ior.right(1)));
//Ior.right(Seq.of(10,1)));
iors
- Iors to sequencestatic <L,T> Ior<L,ReactiveSeq<T>> sequence(ReactiveSeq<? extends Ior<L,T>> stream)
static <L,T,R> Ior<L,ReactiveSeq<R>> traverse(java.util.function.Function<? super T,? extends R> fn, ReactiveSeq<Ior<L,T>> stream)
static <ST,PT,R> Ior<ST,R> accumulateRight(java.lang.Iterable<Ior<ST,PT>> iors, Reducer<R,PT> reducer)
cyclops2.Reducers
.
Ior<String,Integer> just = Ior.right(10);
Ior<String,Integer> none = Ior.left("none");
Ior<?,PersistentSetX<Integer>> iors =Ior.accumulateRight(Seq.of(just,none,Ior.right(1)),Reducers.toPersistentSetX());
//Ior.right(PersistentSetX.of(10,1))));
iors
- Collection of Iors to accumulate right valuesreducer
- Reducer to accumulate resultsstatic <ST,PT,R> Ior<ST,R> accumulateRight(java.lang.Iterable<Ior<ST,PT>> iors, java.util.function.Function<? super PT,R> mapper, Semigroup<R> reducer)
cyclops2.SemigroupK
.
Ior<String,Integer> just = Ior.right(10);
Ior<String,Integer> none = Ior.left("none");
Ior<?,String> iors = Ior.accumulateRight(Seq.of(just,none,Ior.right(1)),i->""+i,SemigroupK.stringConcat);
//Ior.right("101"));
iors
- Collection of Iors to accumulate right valuesmapper
- Mapping function to be applied to the result of each Iorreducer
- Reducer to accumulate resultsstatic <ST,PT> Ior<ST,PT> accumulateRight(java.lang.Iterable<Ior<ST,PT>> iors, Semigroup<PT> reducer)
cyclops2.SemigroupK
.
Ior<String,Integer> just = Ior.right(10);
Ior<String,Integer> none = Ior.left("none");
Ior<?,Integer> iors =Ior.accumulateRight(Seq.of(just,none,Ior.right(1)),SemigroupK.intSum);
//Ior.right(11);
iors
- Collection of Iors to accumulate right valuesreducer
- Reducer to accumulate resultsdefault <U> Option<U> ofType(java.lang.Class<? extends U> type)
Filters
// (1, 2, 3) ReactiveSeq.of(1, "a", 2, "b",3).ofType(Integer.class)
default Option<RT> filterNot(java.util.function.Predicate<? super RT> fn)
Filters
of(1,2,3).filter(i->i>2);
//[1,2]
default Option<RT> notNull()
Filters
of(1,2,null,4).nonNull();
//[1,2,4]
default Ior<LT,RT> bipeek(java.util.function.Consumer<? super LT> c1, java.util.function.Consumer<? super RT> c2)
BiTransformable
MapX<String,Integer> map = MapXs.of("hello",2);
map.bipeek(s->System.out.pritnln("key = " + s),System.out::println);
bipeek
in interface BiTransformable<LT,RT>
c1
- consumer for the first typec2
- consumer for the second typedefault <T2,R> Ior<LT,R> zip(Ior<LT,? extends T2> app, java.util.function.BiFunction<? super RT,? super T2,? extends R> fn)
default <T2,R> Ior<LT,R> zip(Either<LT,? extends T2> app, java.util.function.BiFunction<? super RT,? super T2,? extends R> fn)
static <ST,T> Ior<ST,T> narrowK2(Higher2<DataWitness.ior,ST,T> ior)
static <ST,T> Ior<ST,T> narrowK(Higher<Higher<DataWitness.ior,ST>,T> ior)