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