question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Create Maybe from null in RxJava 2.0.4

See original GitHub issue

Hi,

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:closed
  • Created 7 years ago
  • Reactions:11
  • Comments:13 (6 by maintainers)

github_iconTop GitHub Comments

15reactions
davidmotencommented, Jan 27, 2017

Maybe.fromCallable(() -> null) is good to know about, thanks.

In general I think even simple convenience methods should be considered for the API because

  • it can improve peoples perception of the ease of use of the api
  • it prevents people having to write these simple methods and their unit tests themselves
  • it prevents people needing to add external libraries to their project

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.

13reactions
akarnokdcommented, Jan 25, 2017

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found