@@ -440,7 +440,7 @@ public static <T> Maybe<T> just(T item) {
440
440
ObjectHelper .requireNonNull (item , "item is null" );
441
441
return RxJavaPlugins .onAssembly (new MaybeJust <T >(item ));
442
442
}
443
-
443
+
444
444
/**
445
445
* Merges an Iterable sequence of MaybeSource instances into a single Flowable sequence,
446
446
* running all MaybeSources at once.
@@ -700,6 +700,33 @@ public static <T> Maybe<T> wrap(MaybeSource<T> source) {
700
700
// Instance methods
701
701
// ------------------------------------------------------------------
702
702
703
+ /**
704
+ * Waits in a blocking fashion until the current Maybe signals a success value (which is returned) or
705
+ * defaultValue if completed or an exception (which is propagated).
706
+ * <dl>
707
+ * <dt><b>Scheduler:</b></dt>
708
+ * <dd>{@code blockingGet} does not operate by default on a particular {@link Scheduler}.</dd>
709
+ * </dl>
710
+ * @return the success value
711
+ */
712
+ public T blockingGet () {
713
+ return MaybeAwait .get (this , null );
714
+ }
715
+
716
+ /**
717
+ * Waits in a blocking fashion until the current Maybe signals a success value (which is returned) or
718
+ * defaultValue if completed or an exception (which is propagated).
719
+ * <dl>
720
+ * <dt><b>Scheduler:</b></dt>
721
+ * <dd>{@code blockingGet} does not operate by default on a particular {@link Scheduler}.</dd>
722
+ * </dl>
723
+ * @return the success value
724
+ */
725
+ public T blockingGet (T defaultValue ) {
726
+ ObjectHelper .requireNonNull (defaultValue , "defaultValue is null" );
727
+ return MaybeAwait .get (this , defaultValue );
728
+ }
729
+
703
730
/**
704
731
* Casts the success value of the current Maybe into the target type or signals a
705
732
* ClassCastException if not compatible.
@@ -739,7 +766,7 @@ public final <U> Maybe<U> cast(final Class<? extends U> clazz) {
739
766
public final <R > Maybe <R > compose (Function <? super Maybe <T >, ? extends MaybeSource <R >> transformer ) {
740
767
return wrap (to (transformer ));
741
768
}
742
-
769
+
743
770
/**
744
771
* Returns a Maybe that is based on applying a specified function to the item emitted by the source Maybe,
745
772
* where that function returns a MaybeSource.
@@ -857,7 +884,7 @@ public final Maybe<T> doOnError(Consumer<? super Throwable> onError) {
857
884
Functions .EMPTY_ACTION // dispose
858
885
));
859
886
}
860
-
887
+
861
888
/**
862
889
* Calls the given onEvent callback with the (success value, null) for an onSuccess, (null, throwabe) for
863
890
* an onError or (null, null) for an onComplete signal from this Maybe before delivering said
@@ -964,6 +991,69 @@ public final <R> Maybe<R> flatMap(Function<? super T, ? extends MaybeSource<? ex
964
991
return RxJavaPlugins .onAssembly (new MaybeFlatten <T , R >(this , mapper ));
965
992
}
966
993
994
+ /**
995
+ * Returns a Observable that is based on applying a specified function to the item emitted by the source Maybe,
996
+ * where that function returns a ObservableSource.
997
+ * <p>
998
+ * <img width="640" height="300" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/Maybe.flatMap.png" alt="">
999
+ * <dl>
1000
+ * <dt><b>Scheduler:</b></dt>
1001
+ * <dd>{@code flatMap} does not operate by default on a particular {@link Scheduler}.</dd>
1002
+ * </dl>
1003
+ *
1004
+ * @param <R> the result value type
1005
+ * @param mapper
1006
+ * a function that, when applied to the item emitted by the source Maybe, returns a ObservableSource
1007
+ * @return the Observable returned from {@code func} when applied to the item emitted by the source Maybe
1008
+ * @see <a href="http://reactivex.io/documentation/operators/flatmap.html">ReactiveX operators documentation: FlatMap</a>
1009
+ */
1010
+ public final <R > Observable <R > flatMapObservable (Function <? super T , ? extends ObservableSource <? extends R >> mapper ) {
1011
+ return toObservable ().flatMap (mapper );
1012
+ }
1013
+
1014
+ /**
1015
+ * Returns a Flowable that emits items based on applying a specified function to the item emitted by the
1016
+ * source Maybe, where that function returns a Publisher.
1017
+ * <p>
1018
+ * <img width="640" height="305" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/Single.flatMapObservable.png" alt="">
1019
+ * <dl>
1020
+ * <dt><b>Scheduler:</b></dt>
1021
+ * <dd>{@code flatMapObservable} does not operate by default on a particular {@link Scheduler}.</dd>
1022
+ * </dl>
1023
+ *
1024
+ * @param <R> the result value type
1025
+ * @param mapper
1026
+ * a function that, when applied to the item emitted by the source Maybe, returns an
1027
+ * Flowable
1028
+ * @return the Flowable returned from {@code func} when applied to the item emitted by the source Maybe
1029
+ * @see <a href="http://reactivex.io/documentation/operators/flatmap.html">ReactiveX operators documentation: FlatMap</a>
1030
+ */
1031
+ public final <R > Flowable <R > flatMapPublisher (Function <? super T , ? extends Publisher <? extends R >> mapper ) {
1032
+ return toFlowable ().flatMap (mapper );
1033
+ }
1034
+
1035
+ /**
1036
+ * Returns a {@link Completable} that completes based on applying a specified function to the item emitted by the
1037
+ * source {@link Single}, where that function returns a {@link Completable}.
1038
+ * <p>
1039
+ * <img width="640" height="305" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/Single.flatMapCompletable.png" alt="">
1040
+ * <dl>
1041
+ * <dt><b>Scheduler:</b></dt>
1042
+ * <dd>{@code flatMapCompletable} does not operate by default on a particular {@link Scheduler}.</dd>
1043
+ * </dl>
1044
+ *
1045
+ * @param mapper
1046
+ * a function that, when applied to the item emitted by the source Single, returns a
1047
+ * Completable
1048
+ * @return the Completable returned from {@code func} when applied to the item emitted by the source Single
1049
+ * @see <a href="http://reactivex.io/documentation/operators/flatmap.html">ReactiveX operators documentation: FlatMap</a>
1050
+ * @since 2.0
1051
+ */
1052
+ public final Completable flatMapCompletable (final Function <? super T , ? extends Completable > mapper ) {
1053
+ ObjectHelper .requireNonNull (mapper , "mapper is null" );
1054
+ return RxJavaPlugins .onAssembly (new MaybeFlatMapCompletable <T >(this , mapper ));
1055
+ }
1056
+
967
1057
/**
968
1058
* Maps the onSuccess, onError or onComplete signals of this Maybe into MaybeSource and emits that
969
1059
* MaybeSource's signals
@@ -1148,6 +1238,20 @@ public final Observable<T> toObservable() {
1148
1238
return RxJavaPlugins .onAssembly (new MaybeToObservable <T >(this ));
1149
1239
}
1150
1240
1241
+ /**
1242
+ * Converts this Maybe into an Single instance composing cancellation
1243
+ * through and turing an empty Maybe into a signal of NoSuchElementException.
1244
+ * <dl>
1245
+ * <dt><b>Scheduler:</b></dt>
1246
+ * <dd>{@code create} does not operate by default on a particular {@link Scheduler}.</dd>
1247
+ * </dl>
1248
+ * @return the new Single instance
1249
+ */
1250
+ public final Single <T > toSingle (T defaultValue ) {
1251
+ ObjectHelper .requireNonNull (defaultValue , "defaultValue is null" );
1252
+ return RxJavaPlugins .onAssembly (new MaybeToSingle <T >(this , defaultValue ));
1253
+ }
1254
+
1151
1255
/**
1152
1256
* Converts this Maybe into an Single instance composing cancellation
1153
1257
* through and turing an empty Maybe into a signal of NoSuchElementException.
@@ -1158,7 +1262,7 @@ public final Observable<T> toObservable() {
1158
1262
* @return the new Single instance
1159
1263
*/
1160
1264
public final Single <T > toSingle () {
1161
- return RxJavaPlugins .onAssembly (new MaybeToSingle <T >(this ));
1265
+ return RxJavaPlugins .onAssembly (new MaybeToSingle <T >(this , null ));
1162
1266
}
1163
1267
1164
1268
/**
0 commit comments