Create Maybe from null in RxJava 2.0.4
See original GitHub issueHi,
I wanted to created Maybe from null. When using Java 8 Optional there is ofNullable
. In RxJava this can be achieved with:
Data nullableData = getNullableData();
Maybe<Data> maybe = nullableData == null ? Maybe.empty() : Maybe.just(nullableData);
Instead I’d prefer to use something like:
Data nullableData = getNullableData();
Maybe<Data> maybe = Maybe.ofNullable(nullableData);
Will similar method be added in any future release?
Best regards Aleksander Mieczarek
Issue Analytics
- State:
- Created 7 years ago
- Reactions:11
- Comments:13 (6 by maintainers)
Top Results From Across the Web
How to handle null in Single<T> RxJava 2.0 - vegeta - Medium
From RxJava2 release one of the important changes is that null is no longer accepted as a stream element. Actually, the value '...
Read more >How to pass null to an Observable with nullable type in ...
Since RxJava 2 does not support null values, there are some other ... Observable.create { observer -> upstreamService.listen(object: ...
Read more >Maybe (RxJava Javadoc 3.1.5) - ReactiveX
Returns a Future representing the single value emitted by the current Maybe or null if the current Maybe is empty. @NonNull Observable<T>, toObservable()....
Read more >Maybe (RxJava Javadoc 2.1.7)
Returns a Maybe that invokes passed function and emits its result for each new MaybeObserver that subscribes while considering null value from the...
Read more >Using RxJava 2 - Tutorial - Vogella.com
Maybe <List<Todo>> todoMaybe = Maybe.create(emitter -> { try { List<Todo> todos = getTodos(); if(todos != null && !todos.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Maybe.fromCallable(() -> null)
is good to know about, thanks.In general I think even simple convenience methods should be considered for the API because
Having said that I appreciate the impact of any api addition in the areas you mentioned. I’m happy to pass on this addition and see how much this comes up in the future.
Source-like operators don’t have to live in RxJava. You can have your own static factory method anywhere.
Also
Maybe.fromCallable(() -> null)
is permitted.