use of cyclops.control.Maybe in project cyclops by aol.
the class AnyMTest method flatMapValueFirstQueue.
@Test
public void flatMapValueFirstQueue() {
Maybe l = AnyM.fromMaybe(Maybe.of(1)).concatMap(i -> QueueX.of(10, i)).toMaybe();
assertThat(l, equalTo(Maybe.of(10)));
}
use of cyclops.control.Maybe in project cyclops by aol.
the class AnyMTest method flatMapValueFirstList.
@Test
public void flatMapValueFirstList() {
Maybe l = AnyM.fromMaybe(Maybe.of(1)).concatMap(i -> ListX.of(10, i)).toMaybe();
assertThat(l, equalTo(Maybe.of(10)));
}
use of cyclops.control.Maybe in project cyclops by aol.
the class FlowableReactiveSeqImpl method single.
@Override
public Maybe<T> single() {
Maybe.CompletableMaybe<T, T> maybe = Maybe.<T>maybe();
flowable.subscribe(new Subscriber<T>() {
Object value = UNSET;
Subscription sub;
@Override
public void onSubscribe(Subscription s) {
this.sub = s;
s.request(Long.MAX_VALUE);
}
@Override
public void onNext(T t) {
if (value == UNSET)
value = t;
else {
maybe.completeAsNone();
sub.cancel();
}
}
@Override
public void onError(Throwable t) {
maybe.completeExceptionally(t);
}
@Override
public void onComplete() {
if (value == UNSET)
maybe.completeAsNone();
else
maybe.complete((T) value);
}
});
return maybe;
}
use of cyclops.control.Maybe in project cyclops by aol.
the class AnyMTest method flatMapValueFirstFlux.
@Test
public void flatMapValueFirstFlux() {
Maybe l = AnyM.fromMaybe(Maybe.of(1)).mergeMap(i -> Flux.just(10, i)).unwrap();
assertThat(l, equalTo(Maybe.of(10)));
}
use of cyclops.control.Maybe in project cyclops by aol.
the class AnyMTest method flatMapValueFirstSet.
@Test
public void flatMapValueFirstSet() {
Maybe l = AnyM.fromMaybe(Maybe.of(1)).concatMap(i -> SetX.of(10, i)).toMaybe();
assertThat(l.toOptional().get(), instanceOf(Integer.class));
}
Aggregations