RxOptional extends Maybe<T> { public <U> Observable<U> flatten(Function<T, Iterable<? extends U>> mapper) { return delegate.flattenAsObservable(mapper); } private  RxOptional(); private  RxOptional(T value); static RxOptional<T> maybe(T value); @SuppressWarnings("unchecked") static RxOptional<T> empty(); RxOptional<T> or(T anotherValue); Observable<U> flatten(Function<T, Iterable<? extends U>> mapper); T get(); @Nonnull RxOptional<T> ifPresent(@Nonnull Consumer<T> consumer); @Nonnull RxOptional<T> ifNotPresent(@Nonnull Action action); @Nonnull RxOptional<T> mapIfNotPresent(@Nonnull Supplier<T> supplier); @Nonnull RxOptional<R> mapIfPresent(@Nonnull Function<T, R> function); @Nonnull RxOptional<T> flatMapIfNotPresent(@Nonnull Supplier<RxOptional<T>> supplier); @Nonnull RxOptional<R> flatMapIfPresent(@Nonnull Function<T, RxOptional<R>> function);  }
@Test public void flatten() { ArrayList<String> strings = new ArrayList<>(Arrays.asList("1", "2", "3")); List<String> actual = RxOptional .maybe(strings) .flatten(a -> a) .filter(s -> !s.equals("2")) .toList() .blockingGet(); assertThat(actual, is(not(strings))); assertThat(actual.size(), is(2)); assertThat(actual.get(0), is("1")); assertThat(actual.get(1), is("3")); }