T
- public interface Maybe<T> extends MonadicValue1<T>, java.util.function.Supplier<T>, ConvertableFunctor<T>, Filterable<T>, ApplicativeFunctor<T>, Matchable.ValueAndOptionalMatcher<T>
{@code
Modifier and Type | Interface and Description |
---|---|
static class |
Maybe.Just<T> |
static class |
Maybe.Lazy<T> |
static class |
Maybe.Nothing<T> |
ApplicativeFunctor.Applicatives, ApplicativeFunctor.ApplyFunctions<T>
Modifier and Type | Method and Description |
---|---|
static <T,R> Maybe<R> |
accumulateJust(CollectionX<Maybe<T>> maybes,
java.util.function.Function<? super T,R> mapper,
Semigroup<R> reducer) |
static <T,R> Maybe<R> |
accumulateJust(CollectionX<Maybe<T>> maybes,
Reducer<R> reducer) |
static <T> Maybe<T> |
accumulateJust(CollectionX<Maybe<T>> maybes,
Semigroup<T> reducer) |
default <U> Maybe<U> |
cast(java.lang.Class<? extends U> type)
Cast all elements in a stream to a given type, possibly throwing a
ClassCastException . |
default <R> Maybe<R> |
coflatMap(java.util.function.Function<? super MonadicValue<T>,R> mapper) |
default <T2,R> Maybe<R> |
combine(Value<? extends T2> app,
java.util.function.BiFunction<? super T,? super T2,? extends R> fn)
Lazily combine this ApplicativeFunctor with the supplied value via the supplied BiFunction
|
default Maybe<T> |
combineEager(Monoid<T> monoid,
MonadicValue<? extends T> v2)
Eagerly combine two MonadicValues using the supplied monoid (@see ApplicativeFunctor for type appropraite i.e.
|
Maybe<T> |
filter(java.util.function.Predicate<? super T> fn)
Keep only elements for which the supplied predicates hold
e.g.
|
default Maybe<T> |
filterNot(java.util.function.Predicate<? super T> fn)
Remove any elements for which the predicate holds (inverse operation to filter)
e.g.
|
<R> Maybe<R> |
flatMap(java.util.function.Function<? super T,? extends MonadicValue<? extends R>> mapper) |
static <T> Maybe<T> |
fromEvalOf(Eval<T> eval) |
static <T> Maybe<T> |
fromIterable(java.lang.Iterable<T> iterable) |
static <T> Maybe<T> |
fromOptional(java.util.Optional<T> opt) |
static <T> Maybe<T> |
fromPublisher(org.reactivestreams.Publisher<T> pub) |
boolean |
isPresent() |
static <T> Maybe<T> |
just(T value) |
<R> Maybe<R> |
map(java.util.function.Function<? super T,? extends R> mapper)
Transform this functor using the supplied transformation function
|
static <T> Maybe<T> |
narrow(Maybe<? extends T> broad) |
default Maybe<MonadicValue<T>> |
nest() |
static <T> Maybe<T> |
none() |
default Maybe<T> |
notNull()
Filter elements retaining only values which are not null
|
static <T> Maybe<T> |
of(T value) |
static <T> Maybe<T> |
ofNullable(T value) |
default <U> Maybe<U> |
ofType(java.lang.Class<? extends U> type)
Keep only those elements in a stream that are of a given type.
|
default <R> Maybe<R> |
patternMatch(java.util.function.Function<Matchable.CheckValue1<T,R>,Matchable.CheckValue1<T,R>> case1,
java.util.function.Supplier<? extends R> otherwise)
Transform the elements of this Stream with a Pattern Matching case and default value
|
default Maybe<T> |
peek(java.util.function.Consumer<? super T> c)
Peek at the current value of this Functor, without transforming it
|
Maybe<T> |
recover(java.util.function.Supplier<T> value) |
Maybe<T> |
recover(T value) |
static <T> Maybe<ListX<T>> |
sequence(CollectionX<Maybe<T>> maybes) |
static <T> Maybe<ReactiveSeq<T>> |
sequence(java.util.stream.Stream<Maybe<T>> maybes) |
static <T> Maybe<ListX<T>> |
sequenceJust(CollectionX<Maybe<T>> opts) |
default Maybe<T> |
toMaybe() |
default <R> Maybe<R> |
trampoline(java.util.function.Function<? super T,? extends Trampoline<? extends R>> mapper)
Performs a map operation that can call a recursive method without running out of stack space
|
default <T> Maybe<T> |
unit(T unit) |
<R> R |
visit(java.util.function.Function<? super T,? extends R> some,
java.util.function.Supplier<? extends R> none) |
default <T2,R> Maybe<R> |
zip(java.util.function.BiFunction<? super T,? super T2,? extends R> fn,
org.reactivestreams.Publisher<? extends T2> app)
Equivalent to combine, but accepts a Publisher and takes the first value only from that publisher.
|
default <T2,R> Maybe<R> |
zip(java.lang.Iterable<? extends T2> app,
java.util.function.BiFunction<? super T,? super T2,? extends R> fn)
Zip (combine) this Zippable with the supplied Iterable using the supplied combining function
|
default <U> Maybe<org.jooq.lambda.tuple.Tuple2<T,U>> |
zip(java.lang.Iterable<? extends U> other)
Zip (combine) this Zippable with the supplied Iterable combining both into a Tuple2
|
default <U> Maybe<org.jooq.lambda.tuple.Tuple2<T,U>> |
zip(org.jooq.lambda.Seq<? extends U> other)
Zip (combine) this Zippable with the supplied Seq combining both into a Tuple2
|
default <U,R> Maybe<R> |
zip(org.jooq.lambda.Seq<? extends U> other,
java.util.function.BiFunction<? super T,? super U,? extends R> zipper)
Zip (combine) this Zippable with the supplied Seq, using the supplied combining function
|
default <U> Maybe<org.jooq.lambda.tuple.Tuple2<T,U>> |
zip(java.util.stream.Stream<? extends U> other)
Zip (combine) this Zippable with the supplied Stream combining both into a Tuple2
|
default <U,R> Maybe<R> |
zip(java.util.stream.Stream<? extends U> other,
java.util.function.BiFunction<? super T,? super U,? extends R> zipper)
Zip (combine) this Zippable with the supplied Stream, using the supplied combining function
|
anyM
applyFunctions
iterator, toOptional
matches
static final Maybe EMPTY
static <T> Maybe<T> none()
static <T> Maybe<T> fromPublisher(org.reactivestreams.Publisher<T> pub)
static <T> Maybe<T> fromIterable(java.lang.Iterable<T> iterable)
static <T> Maybe<T> fromOptional(java.util.Optional<T> opt)
static <T> Maybe<T> just(T value)
static <T> Maybe<T> ofNullable(T value)
static <T> Maybe<ListX<T>> sequenceJust(CollectionX<Maybe<T>> opts)
static <T> Maybe<ListX<T>> sequence(CollectionX<Maybe<T>> maybes)
static <T> Maybe<ReactiveSeq<T>> sequence(java.util.stream.Stream<Maybe<T>> maybes)
static <T,R> Maybe<R> accumulateJust(CollectionX<Maybe<T>> maybes, Reducer<R> reducer)
static <T,R> Maybe<R> accumulateJust(CollectionX<Maybe<T>> maybes, java.util.function.Function<? super T,R> mapper, Semigroup<R> reducer)
static <T> Maybe<T> accumulateJust(CollectionX<Maybe<T>> maybes, Semigroup<T> reducer)
default <T2,R> Maybe<R> combine(Value<? extends T2> app, java.util.function.BiFunction<? super T,? super T2,? extends R> fn)
ApplicativeFunctor
combine
in interface ApplicativeFunctor<T>
app
- Value to combine with this one.fn
- BiFunction to combine themdefault <T2,R> Maybe<R> zip(java.lang.Iterable<? extends T2> app, java.util.function.BiFunction<? super T,? super T2,? extends R> fn)
Zippable
default <T2,R> Maybe<R> zip(java.util.function.BiFunction<? super T,? super T2,? extends R> fn, org.reactivestreams.Publisher<? extends T2> app)
default <U,R> Maybe<R> zip(org.jooq.lambda.Seq<? extends U> other, java.util.function.BiFunction<? super T,? super U,? extends R> zipper)
Zippable
default <U,R> Maybe<R> zip(java.util.stream.Stream<? extends U> other, java.util.function.BiFunction<? super T,? super U,? extends R> zipper)
Zippable
default <U> Maybe<org.jooq.lambda.tuple.Tuple2<T,U>> zip(java.util.stream.Stream<? extends U> other)
Zippable
default <U> Maybe<org.jooq.lambda.tuple.Tuple2<T,U>> zip(org.jooq.lambda.Seq<? extends U> other)
Zippable
default <U> Maybe<org.jooq.lambda.tuple.Tuple2<T,U>> zip(java.lang.Iterable<? extends U> other)
Zippable
default <T> Maybe<T> unit(T unit)
unit
in interface MonadicValue<T>
unit
in interface MonadicValue1<T>
unit
in interface Unit<T>
default <R> Maybe<R> coflatMap(java.util.function.Function<? super MonadicValue<T>,R> mapper)
coflatMap
in interface MonadicValue<T>
coflatMap
in interface MonadicValue1<T>
default Maybe<MonadicValue<T>> nest()
nest
in interface MonadicValue<T>
default Maybe<T> combineEager(Monoid<T> monoid, MonadicValue<? extends T> v2)
MonadicValue1
Monoid<Integer> add = Monoid.of(1,Semigroups.intSum);
Maybe.of(10).combineEager(add,Maybe.none());
//Maybe[10]
Maybe.none().combineEager(add,Maybe.of(10));
//Maybe[10]
Maybe.none().combineEager(add,Maybe.none());
//Maybe.none()
Maybe.of(10).combineEager(add,Maybe.of(10));
//Maybe[20]
Monoid<Integer> firstNonNull = Monoid.of(null , Semigroups.firstNonNull());
Maybe.of(10).combineEager(firstNonNull,Maybe.of(10));
//Maybe[10]
combineEager
in interface MonadicValue1<T>
boolean isPresent()
isPresent
in interface Convertable<T>
<R> Maybe<R> map(java.util.function.Function<? super T,? extends R> mapper)
Functor
of(1,2,3).map(i->i*2)
//[2,4,6]
map
in interface ConvertableFunctor<T>
map
in interface Functor<T>
map
in interface MonadicValue<T>
map
in interface MonadicValue1<T>
mapper
- Transformation function<R> Maybe<R> flatMap(java.util.function.Function<? super T,? extends MonadicValue<? extends R>> mapper)
flatMap
in interface MonadicValue1<T>
<R> R visit(java.util.function.Function<? super T,? extends R> some, java.util.function.Supplier<? extends R> none)
visit
in interface Convertable<T>
visit
in interface Matchable.MatchableOptional<T>
visit
in interface Matchable.ValueAndOptionalMatcher<T>
visit
in interface Visitable<T>
Maybe<T> filter(java.util.function.Predicate<? super T> fn)
Filterable
of(1,2,3).filter(i->i>2);
//[3]
filter
in interface Filterable<T>
fn
- to filter elements by, retaining matchesdefault <U> Maybe<U> ofType(java.lang.Class<? extends U> type)
Filterable
// (1, 2, 3) ReactiveSeq.of(1, "a", 2, "b",3).ofType(Integer.class)
ofType
in interface Filterable<T>
default Maybe<T> filterNot(java.util.function.Predicate<? super T> fn)
Filterable
of(1,2,3).filter(i->i>2);
//[1,2]
filterNot
in interface Filterable<T>
fn
- to filter elements by, retaining matchesdefault Maybe<T> notNull()
Filterable
of(1,2,null,4).nonNull();
//[1,2,4]
notNull
in interface Filterable<T>
default <U> Maybe<U> cast(java.lang.Class<? extends U> type)
Functor
ClassCastException
.
// ClassCastException ReactiveSeq.of(1, "a", 2, "b", 3).cast(Integer.class)default Maybe<T> peek(java.util.function.Consumer<? super T> c)
Functor
of(1,2,3).map(System.out::println)
1
2
3
default <R> Maybe<R> trampoline(java.util.function.Function<? super T,? extends Trampoline<? extends R>> mapper)
Functor
ReactiveSeq.of(10,20,30,40)
.trampoline(i-> fibonacci(i))
.forEach(System.out::println);
Trampoline<Long> fibonacci(int i){
return fibonacci(i,1,0);
}
Trampoline<Long> fibonacci(int n, long a, long b) {
return n == 0 ? Trampoline.done(b) : Trampoline.more( ()->fibonacci(n-1, a+b, a));
}
55
6765
832040
102334155
ReactiveSeq.of(10_000,200_000,3_000_000,40_000_000)
.trampoline(i-> fibonacci(i))
.forEach(System.out::println);
completes successfully
trampoline
in interface Functor<T>
mapper
- TCO Transformation functiondefault <R> Maybe<R> patternMatch(java.util.function.Function<Matchable.CheckValue1<T,R>,Matchable.CheckValue1<T,R>> case1, java.util.function.Supplier<? extends R> otherwise)
Functor
List<String> result = CollectionX.of(1,2,3,4)
.patternMatch(
c->c.valuesWhere(i->"even", (Integer i)->i%2==0 )
)
// CollectionX["odd","even","odd","even"]
patternMatch
in interface Functor<T>
case1
- Function to generate a case (or chain of cases as a single case)otherwise
- Value if supplied case doesn't match