I was looking at RxJava Single, and there is two operators that I need and I would like to add on RxSwift.
flatMapMaybe - Same as flatMap but returns a Maybe;toMaybe - Convert Single to Maybe.Do you think it鈥檚 worth to adding these operators?
If so, I am able to do this and open a pull request.
Thanks!
I agree add flatMap overloding(or add flatMap*) but not only Maybe.
I explain why we need them in this comment. https://github.com/ReactiveX/RxSwift/issues/1206#issuecomment-358182422
I wish add there implementation, maybe important thing is naming.
Hi @tarunon
I was on vacation and without my mac.
Sorry for missing the related issue #1206
I will update the PR #1582 and add more operators!
Hi,
@pietrocaselani I think that we should go one operator at a time.
@tarunon I've just seen your https://github.com/ReactiveX/RxSwift/issues/1206#issuecomment-358182422 . I usually never look at comments after an issue has been closed. It is usually a good idea to either reopen the issue if you feel it shouldn't be closed, or open a new one.
I think we would probably need to encode return value into operator name to avoid ambiguity issues, which could be a bit ugly.
But I think it could make sense.
@kzaher
I'm sorry I forgot reopen that issue.
Yes, I try to implement add https://github.com/ReactiveX/RxSwift/issues/1206#issuecomment-358182422 way, but I found some of ambiguous compile error. I think making the function name as flatMapMaybe and flatMapCompletable are good. Thank you.
@kzaher do you think we could merge #1582 for now? Then, I could create new PRs for the new operators.
Hi @pietrocaselani @tarunon ,
yes, I've glanced at #1582, seemed reasonable to me. I'll probably merge it, but I would like to first conceptually think about the API for other methods.
There is a slight inconsistency with naming since:
flatMap: Single -> SingleflatMapMaybe: Maybe -> MaybeflatMap: Maybe -> MaybeflatMapSingle: Maybe -> MaybeI would like to first figure out is there something more consistent.
Thoughts?
I was thinking something like this
On Single trait:
flatMap: Single -> SingleflatMapMaybe: Single -> MaybeflatMapCompletable: Single -> CompletableasMaybe: Single -> MaybeasCompletable: Single -> CompletableOn Maybe trait:
flatMap: Maybe -> MaybeflatMapSingle: Maybe -> SingleflatMapCompletable: Maybe -> CompletableasSingle(defaultElement: E): Maybe -> Singlebut we could create small PRs to implement those operators one by one.
All those operators are available on RxJava.
Hi @kzaher @pietrocaselani
I think Maybe to Single translate is not stable, we should not add these operator, IMO.
This table is what should make result Sequence from source Sequenece and closure returnining Sequenece.
|Source锛糃losure|(T) -> Single<U>|(T) -> Maybe<U>|(T) -> Completable|
|---|---|---|---|
|Single<T>|Single<U>|Maybe<U>|Completable|
|Maybe<T>|Maybe<U>|Maybe<U>|Completable|
Source Sequence and closure returning Sequence type is just like a Boolean's and operator.
Source Sequence is Single and returning Sequence Single then result is Single,
if one is Maybe then result is Maybe,
and one is Completable then result is Completable. That's make sense.
@tarunon
Yes, Maybe to Single flatMap shouldn't be possible as far as I can tell.
Sorry for taking to long to creating those PRs.
I was looking the code necessary to create the operator Maybe.flatMapCompletable, but first, I need to implement Observable.flatMapCompletable, which is available on RxJava
I will open a PR with just this operator, after that, I open another PR adding to maybe trait.
Hi @pietrocaselani,
Let us first figure out only what are the convenience operators we can add.
They will get us the most benefits for now, and bloat the codebase the least.
@kzaher I will open a PR only adding Maybe.flatMapCompletable, after that, we can talk about adding or not more operators.
I understand your worries about bloating the codebase, but I think that those operators are important to keep the composition, not breaking the flow, and I think it's a good idea keeping consistency with RxJava, but let me know if you disagree.
Hi @pietrocaselani ,
is this just using the normal flatMap operator?
@kzaher are you talking about Maybe.flatMapCompletable? It's a flatMap but returns a Completable trait. http://reactivex.io/RxJava/2.x/javadoc/io/reactivex/Maybe.html#flatMapCompletable-io.reactivex.functions.Function-
Hi, since asCompletable operator is now implemented on Single (#1651), are there any plans to implement similar operator on Maybe? RxJava have it and call it ignoreElement (https://github.com/ReactiveX/RxJava/blob/2.x/README.md#user-content-converting-to-the-desired-type).
If you agree with adding this operator, I would volunteer to implement it.
What is missing here? This is quite old so I prefer to close it. It seems to me it was mostly solved here: https://github.com/ReactiveX/RxSwift/pull/1582 ?
If there are additional pieces of work you feel missing, let's extract those to a new issue so it's less confusing and easier to track.
I feel ok closing this.
It's still missing some operators from RxJava, but if I need them I create another PR.
Sounds good to me. Thanks !
Most helpful comment
Hi, since
asCompletableoperator is now implemented onSingle(#1651), are there any plans to implement similar operator onMaybe? RxJava have it and call itignoreElement(https://github.com/ReactiveX/RxJava/blob/2.x/README.md#user-content-converting-to-the-desired-type).If you agree with adding this operator, I would volunteer to implement it.