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