T
- The type contained on the Xor withinpublic class XorT<T>
extends java.lang.Object
Modifier and Type | Method and Description |
---|---|
XorT<T> |
filter(java.util.function.Predicate<? super T> test)
Filter the wrapped Xor
|
<B> XorT<B> |
flatMap(java.util.function.Function<? super T,XorT<? extends B>> f)
Flat Map the wrapped Xor
|
static <A> XorT<A> |
fromAnyM(AnyM<A> anyM)
|
static <U,R> java.util.function.Function<XorT<U>,XorT<R>> |
lift(java.util.function.Function<? super U,? extends R> fn)
Lift a function into one that accepts and returns an XorT This allows
multiple monad types to add functionality to existing functions and
methods
e.g.
|
static <U1,U2,R> java.util.function.BiFunction<XorT<U1>,XorT<U2>,XorT<R>> |
lift2(java.util.function.BiFunction<? super U1,? super U2,? extends R> fn)
Lift a BiFunction into one that accepts and returns XorTs This allows
multiple monad types to add functionality to existing functions and
methods
e.g.
|
<B> XorT<B> |
map(java.util.function.Function<? super T,? extends B> f)
Map the wrapped Xor
|
static <A> XorT<A> |
of(AnyM<Xor<?,A>> monads)
Construct an XorT from an AnyM that wraps a monad containing Xors
|
XorT<T> |
peek(java.util.function.Consumer<? super T> peek)
Peek at the current value of the Xor
|
java.lang.String |
toString() |
AnyM<Xor<?,T>> |
unwrap() |
public XorT<T> peek(java.util.function.Consumer<? super T> peek)
XorT.of(AnyM.fromStream(Xor.of(10))
.peek(System.out::println);
//prints 10
peek
- Consumer to accept current value of Xorpublic XorT<T> filter(java.util.function.Predicate<? super T> test)
XorT.of(AnyM.fromStream(Xor.of(10))
.filter(t->t!=10);
//XorT<AnyM<Stream<Xor.empty>>>
test
- Predicate to filter the wrapped Xorpublic <B> XorT<B> map(java.util.function.Function<? super T,? extends B> f)
XorT.of(AnyM.fromStream(Xor.of(10))
.map(t->t=t+1);
//XorT<AnyM<Stream<Xor[11]>>>
f
- Mapping function for the wrapped Xorpublic <B> XorT<B> flatMap(java.util.function.Function<? super T,XorT<? extends B>> f)
XorT.of(AnyM.fromStream(Xor.of(10))
.flatMap(t->Xor.empty();
//XorT<AnyM<Stream<Xor.empty>>>
f
- FlatMap functionpublic static <U,R> java.util.function.Function<XorT<U>,XorT<R>> lift(java.util.function.Function<? super U,? extends R> fn)
{ @code Functionadd2 = i -> i + 2; Function , XorT > optTAdd2 = XorT.lift(add2); Stream withNulls = Stream.of(1, 2, null); AnyM stream = AnyM.ofMonad(withNulls); AnyM > streamOpt = stream.map(Xor::ofNullable); List results = optTAdd2.apply(XorT.of(streamOpt)).unwrap(). >> unwrap() .filter(Xor::isPresent).map(Xor::get).collect(Collectors.toList()); // Arrays.asList(3,4); }
fn
- Function to enhance with functionality from Xor and another
monad typepublic static <U1,U2,R> java.util.function.BiFunction<XorT<U1>,XorT<U2>,XorT<R>> lift2(java.util.function.BiFunction<? super U1,? super U2,? extends R> fn)
{ @code BiFunctionadd = (a, b) -> a + b; BiFunction , XorT , XorT > optTAdd2 = XorT.lift2(add); Stream withNulls = Stream.of(1, 2, null); AnyM stream = AnyM.ofMonad(withNulls); AnyM > streamOpt = stream.map(Xor::ofNullable); CompletableFuture > two = CompletableFuture.supplyAsync(() -> Xor.of(2)); AnyM > future = AnyM.ofMonad(two); List results = optTAdd2.apply(XorT.of(streamOpt), XorT.of(future)).unwrap() . >> unwrap().filter(Xor::isPresent).map(Xor::get) .collect(Collectors.toList()); // Arrays.asList(3,4); }
fn
- BiFunction to enhance with functionality from Xor and
another monad typepublic static <A> XorT<A> fromAnyM(AnyM<A> anyM)
anyM
- AnyM that doesn't contain a monad wrapping an Xorpublic static <A> XorT<A> of(AnyM<Xor<?,A>> monads)
monads
- AnyM that contains a monad wrapping an Xorpublic java.lang.String toString()
toString
in class java.lang.Object