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