Skip to content

Commit

Permalink
changed my mind, we won't deprecate these
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasnield committed Jun 24, 2017
1 parent 5e00f50 commit c278332
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 2 deletions.
1 change: 0 additions & 1 deletion src/main/kotlin/io/reactivex/rxkotlin/maybe.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import io.reactivex.Observable
import java.util.concurrent.Callable
import java.util.concurrent.Future

@Deprecated("This will be removed in a future release due to API confusion")
fun <T : Any> T?.toMaybe(): Maybe<T> = Maybe.create { s -> if (this != null) s.onSuccess(this); s.onComplete() }

This comment has been minimized.

Copy link
@marcinsus

marcinsus Jul 5, 2017

Why you not use Maybe.just and Maybe.empty? This will be more effecient way and you can use better kotlin synax.

This comment has been minimized.

Copy link
@marcinsus

marcinsus Jul 5, 2017

Also onComplete is not nesesery when onSuccess is called.

This comment has been minimized.

Copy link
@thomasnield

thomasnield Jul 5, 2017

Author Collaborator

If you pass a nullable value to Maybe.just(), RxJava2 will throw an error because it does not send null emissions. This targets a nullable type and will turn it into a Maybe that converts nullability into an empty state.

This comment has been minimized.

Copy link
@marcinsus

marcinsus Jul 6, 2017

Of course but you can use already cached Empty-Maybe Instance instead create always the new one.
Preview:
fun <T : Any> T?.toMaybe(): Maybe<T> = this?.let { Maybe.just(it) } ?: Maybe.empty()

This comment has been minimized.

Copy link
@stepango

stepango via email Jul 6, 2017

Collaborator

This comment has been minimized.

Copy link
@marcinsus

marcinsus Jul 6, 2017

Yeap, because of that you do not need to use Maybe.create

This comment has been minimized.

Copy link
@stepango

stepango via email Jul 7, 2017

Collaborator

This comment has been minimized.

Copy link
@marcinsus

marcinsus Jul 7, 2017

Maybe.create always create new MaybeCreate object.
In case:

null.toMaybe()
null.toMaybe()

two objects will be created instead use Maybe.empty() static instance.

fun <T : Any> Future<T>.toMaybe(): Maybe<T> = Maybe.fromFuture(this)
fun <T : Any> Callable<T>.toMaybe(): Maybe<T> = Maybe.fromCallable(this)
Expand Down
1 change: 0 additions & 1 deletion src/main/kotlin/io/reactivex/rxkotlin/single.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import io.reactivex.Single
import java.util.concurrent.Callable
import java.util.concurrent.Future

@Deprecated("This will be removed in a future release due to API confusion, use Single.just()")
fun <T : Any> T.toSingle(): Single<T> = Single.just(this)
fun <T : Any> Future<T>.toSingle(): Single<T> = Single.fromFuture(this)
fun <T : Any> Callable<T>.toSingle(): Single<T> = Single.fromCallable(this)
Expand Down

3 comments on commit c278332

@marcinsus
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For me extension for Any object is very bad idea.

@thomasnield
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason for the extension of Any is to prevent it being done to a nullable type. If you have some specific examples why you think this is suboptimal, please file an issue and we all can discuss...

@thomasnield
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@marcinsus in hindsight, you were absolutely right. Removing these right now.

Please sign in to comment.