@@ -700,6 +700,34 @@ 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),
705
+ * null 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),
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
+ * @param defaultValue the default item to return if this Maybe is empty
724
+ * @return the success value
725
+ */
726
+ public T blockingGet (T defaultValue ) {
727
+ ObjectHelper .requireNonNull (defaultValue , "defaultValue is null" );
728
+ return MaybeAwait .get (this , defaultValue );
729
+ }
730
+
703
731
/**
704
732
* Casts the success value of the current Maybe into the target type or signals a
705
733
* ClassCastException if not compatible.
@@ -996,6 +1024,69 @@ public final <R> Maybe<R> flatMap(
996
1024
return new MaybeFlatMapNotification <T , R >(this , onSuccessMapper , onErrorMapper , onCompleteSupplier );
997
1025
}
998
1026
1027
+ /**
1028
+ * Returns a Observable that is based on applying a specified function to the item emitted by the source Maybe,
1029
+ * where that function returns a ObservableSource.
1030
+ * <p>
1031
+ * <img width="640" height="300" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/Maybe.flatMap.png" alt="">
1032
+ * <dl>
1033
+ * <dt><b>Scheduler:</b></dt>
1034
+ * <dd>{@code flatMap} does not operate by default on a particular {@link Scheduler}.</dd>
1035
+ * </dl>
1036
+ *
1037
+ * @param <R> the result value type
1038
+ * @param mapper
1039
+ * a function that, when applied to the item emitted by the source Maybe, returns a ObservableSource
1040
+ * @return the Observable returned from {@code func} when applied to the item emitted by the source Maybe
1041
+ * @see <a href="http://reactivex.io/documentation/operators/flatmap.html">ReactiveX operators documentation: FlatMap</a>
1042
+ */
1043
+ public final <R > Observable <R > flatMapObservable (Function <? super T , ? extends ObservableSource <? extends R >> mapper ) {
1044
+ return toObservable ().flatMap (mapper );
1045
+ }
1046
+
1047
+ /**
1048
+ * Returns a Flowable that emits items based on applying a specified function to the item emitted by the
1049
+ * source Maybe, where that function returns a Publisher.
1050
+ * <p>
1051
+ * <img width="640" height="305" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/Single.flatMapObservable.png" alt="">
1052
+ * <dl>
1053
+ * <dt><b>Scheduler:</b></dt>
1054
+ * <dd>{@code flatMapObservable} does not operate by default on a particular {@link Scheduler}.</dd>
1055
+ * </dl>
1056
+ *
1057
+ * @param <R> the result value type
1058
+ * @param mapper
1059
+ * a function that, when applied to the item emitted by the source Maybe, returns an
1060
+ * Flowable
1061
+ * @return the Flowable returned from {@code func} when applied to the item emitted by the source Maybe
1062
+ * @see <a href="http://reactivex.io/documentation/operators/flatmap.html">ReactiveX operators documentation: FlatMap</a>
1063
+ */
1064
+ public final <R > Flowable <R > flatMapPublisher (Function <? super T , ? extends Publisher <? extends R >> mapper ) {
1065
+ return toFlowable ().flatMap (mapper );
1066
+ }
1067
+
1068
+ /**
1069
+ * Returns a {@link Completable} that completes based on applying a specified function to the item emitted by the
1070
+ * source {@link Single}, where that function returns a {@link Completable}.
1071
+ * <p>
1072
+ * <img width="640" height="305" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/Single.flatMapCompletable.png" alt="">
1073
+ * <dl>
1074
+ * <dt><b>Scheduler:</b></dt>
1075
+ * <dd>{@code flatMapCompletable} does not operate by default on a particular {@link Scheduler}.</dd>
1076
+ * </dl>
1077
+ *
1078
+ * @param mapper
1079
+ * a function that, when applied to the item emitted by the source Single, returns a
1080
+ * Completable
1081
+ * @return the Completable returned from {@code func} when applied to the item emitted by the source Single
1082
+ * @see <a href="http://reactivex.io/documentation/operators/flatmap.html">ReactiveX operators documentation: FlatMap</a>
1083
+ * @since 2.0
1084
+ */
1085
+ public final Completable flatMapCompletable (final Function <? super T , ? extends Completable > mapper ) {
1086
+ ObjectHelper .requireNonNull (mapper , "mapper is null" );
1087
+ return RxJavaPlugins .onAssembly (new MaybeFlatMapCompletable <T >(this , mapper ));
1088
+ }
1089
+
999
1090
/**
1000
1091
* Ignores the item emitted by the source Maybe and only calls {@code onCompleted} or {@code onError}.
1001
1092
* <p>
@@ -1148,6 +1239,21 @@ public final Observable<T> toObservable() {
1148
1239
return RxJavaPlugins .onAssembly (new MaybeToObservable <T >(this ));
1149
1240
}
1150
1241
1242
+ /**
1243
+ * Converts this Maybe into an Single instance composing cancellation
1244
+ * through and turing an empty Maybe into a signal of NoSuchElementException.
1245
+ * <dl>
1246
+ * <dt><b>Scheduler:</b></dt>
1247
+ * <dd>{@code create} does not operate by default on a particular {@link Scheduler}.</dd>
1248
+ * </dl>
1249
+ * @param defaultValue the default item to signal in Single if this Maybe is empty
1250
+ * @return the new Single instance
1251
+ */
1252
+ public final Single <T > toSingle (T defaultValue ) {
1253
+ ObjectHelper .requireNonNull (defaultValue , "defaultValue is null" );
1254
+ return RxJavaPlugins .onAssembly (new MaybeToSingle <T >(this , defaultValue ));
1255
+ }
1256
+
1151
1257
/**
1152
1258
* Converts this Maybe into an Single instance composing cancellation
1153
1259
* through and turing an empty Maybe into a signal of NoSuchElementException.
@@ -1158,7 +1264,7 @@ public final Observable<T> toObservable() {
1158
1264
* @return the new Single instance
1159
1265
*/
1160
1266
public final Single <T > toSingle () {
1161
- return RxJavaPlugins .onAssembly (new MaybeToSingle <T >(this ));
1267
+ return RxJavaPlugins .onAssembly (new MaybeToSingle <T >(this , null ));
1162
1268
}
1163
1269
1164
1270
/**
0 commit comments