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