T
- public class ListT<T>
extends java.lang.Object
Modifier and Type | Method and Description |
---|---|
ListT<T> |
filter(java.util.function.Predicate<? super T> test)
Filter the wrapped List
|
<B> ListT<B> |
flatMap(org.jooq.lambda.function.Function1<? super T,ListT<B>> f)
Flat Map the wrapped List
|
static <A> ListT<A> |
fromAnyM(AnyM<A> anyM)
|
static <A> ListT<A> |
fromStream(AnyM<java.util.stream.Stream<A>> monads)
Create a ListT from an AnyM that wraps a monad containing a Stream
|
static <U,R> java.util.function.Function<ListT<U>,ListT<R>> |
lift(java.util.function.Function<? super U,? extends R> fn)
Lift a function into one that accepts and returns an ListT
This allows multiple monad types to add functionality to existing functions and methods
e.g.
|
static <U1,U2,R> java.util.function.BiFunction<ListT<U1>,ListT<U2>,ListT<R>> |
lift2(java.util.function.BiFunction<? super U1,? super U2,? extends R> fn)
Lift a BiFunction into one that accepts and returns ListTs
This allows multiple monad types to add functionality to existing functions and methods
e.g.
|
<B> ListT<B> |
map(java.util.function.Function<? super T,? extends B> f)
Map the wrapped List
|
static <A> ListT<A> |
of(AnyM<java.util.List<A>> monads)
Construct an ListT from an AnyM that wraps a monad containing Lists
|
ListT<T> |
peek(java.util.function.Consumer<? super T> peek)
Peek at the current value of the List
|
java.lang.String |
toString() |
AnyM<java.util.List<T>> |
unwrap() |
public ListT<T> peek(java.util.function.Consumer<? super T> peek)
ListT.of(AnyM.fromStream(Arrays.asList(10))
.peek(System.out::println);
//prints 10
peek
- Consumer to accept current value of Listpublic ListT<T> filter(java.util.function.Predicate<? super T> test)
ListT.of(AnyM.fromStream(Arrays.asList(10,11))
.filter(t->t!=10);
//ListT<AnyM<Stream<List[11]>>>
test
- Predicate to filter the wrapped Listpublic <B> ListT<B> map(java.util.function.Function<? super T,? extends B> f)
ListT.of(AnyM.fromStream(Arrays.asList(10))
.map(t->t=t+1);
//ListT<AnyM<Stream<List[11]>>>
f
- Mapping function for the wrapped Listpublic <B> ListT<B> flatMap(org.jooq.lambda.function.Function1<? super T,ListT<B>> f)
ListT.of(AnyM.fromStream(Arrays.asList(10))
.flatMap(t->List.empty();
//ListT<AnyM<Stream<List.empty>>>
f
- FlatMap functionpublic static <U,R> java.util.function.Function<ListT<U>,ListT<R>> lift(java.util.function.Function<? super U,? extends R> fn)
Function<Integer,Integer> add2 = i -> i+2;
Function<ListT<Integer>, ListT<Integer>> optTAdd2 = ListT.lift(add2);
Stream<Integer> nums = Stream.of(1,2);
AnyM<Stream<Integer>> stream = AnyM.ofMonad(Arrays.asList(nums));
List<Integer> results = optTAdd2.apply(ListT.fromStream(stream))
.unwrap()
.<Optional<List<Integer>>>unwrap().get();
//Arrays.asList(3,4);
fn
- Function to enhance with functionality from List and another monad typepublic static <U1,U2,R> java.util.function.BiFunction<ListT<U1>,ListT<U2>,ListT<R>> lift2(java.util.function.BiFunction<? super U1,? super U2,? extends R> fn)
BiFunction<Integer,Integer,Integer> add = (a,b) -> a+b;
BiFunction<ListT<Integer>,ListT<Integer>, ListT<Integer>> optTAdd2 = ListT.lift2(add);
Streamable<Integer> threeValues = Streamable.of(1,2,3);
AnyM<Integer> stream = AnyM.fromStreamable(threeValues);
AnyM<List<Integer>> streamOpt = stream.map(Arrays::asList);
CompletableFuture<List<Integer>> two = CompletableFuture.completedFuture(Arrays.asList(2));
AnyM<List<Integer>> future= AnyM.fromCompletableFuture(two);
List<Integer> results = optTAdd2.apply(ListT.of(streamOpt),ListT.of(future))
.unwrap()
.<Stream<List<Integer>>>unwrap()
.flatMap(i->i.stream())
.collect(Collectors.toList());
//Arrays.asList(3,4);
fn
- BiFunction to enhance with functionality from List and another monad typepublic static <A> ListT<A> fromAnyM(AnyM<A> anyM)
anyM
- AnyM that doesn't contain a monad wrapping an Listpublic static <A> ListT<A> of(AnyM<java.util.List<A>> monads)
monads
- AnyM that contains a monad wrapping an Listpublic static <A> ListT<A> fromStream(AnyM<java.util.stream.Stream<A>> monads)
monads
- public java.lang.String toString()
toString
in class java.lang.Object