-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bike-Shedding: renaming flatMap
, flatMapLatest
for consistency and ease of adoption
#167
Comments
... I guess by this idiom, perhaps |
Again, this is complete and total bike-shedding since this is a full semantic version different. |
Big thumbs up for this proposal.
I think these are two different categories:
The first always takes one Observable as input, the second category always takes at least two Observables as input. I'd say the former are expansion-mapping operators, and the latter are combination operators. (word "expansion" because a value from the source Observable is mapped to an Observable of many values on the resulting Observable) While I think I think Kefir has the best combinator operator. So the static Hence I like Elm's name for combineLatest, which is Regarding Another way of thinking about the combine flavors is: combineLatest is symmetric (all members are active), withLatestFrom is asymmetric (some are active, some are passive). So, tossing Yet another tossed idea is to have
I'm not entirely convinced of all these names, so I'm open to hear some comments, but here is my best bet so far: Expansion-mapping operators:
Combination operators:
|
Ok, giving second thought to it, |
If I am to throw in my $0.02, I would suggest that the mapping strategy need only be specified when it differs from the default "as-is" mode. So Also I think it should be painted forest green. |
@staltz @Blesh |
@Blesh and while |
Isn't there? Isn't the selector function a way of mapping from source events to resulting Observable? I'd say new |
@staltz nope, |
So does Elm's |
Why? No rationale given behind this one, and it doesn't read as clearly as "A mapped with latest from B". |
yes, but Elm is a Haskell dialect and numbers in Haskell methods denote the argument count, a limitation we don't have in JS.
The reason [the current] I'm not saying // mergeMap
Observable.prototype.mergeMap = (selector) => {
return this.map(selector).mergeAll();
};
// zipMap
Observable.prototype.zipMap = (selector) => {
return this.map(selector).zipAll();
}
// zip
Observable.prototype.zip = (...others, selector) => {
return Observable.zip([this].concat(others), selector);
} Another way to put this is that
Just thought I'd throw it in while we're bike-shedding about operators. |
Good point.
Here's the RxJava issue where UPDATE: the discussion from that issue reminded me of a name I proposed for |
@staltz I'm aware of the |
While we're on join, I'll be honest: |
Counter-proposal: Should the formula be
|
I could live with |
That makes perfect sense. If we let go of familiarity, |
And if we do go with Right now |
@staltz as @benjchristensen mentioned in the RxJava thread, |
FYI that we tried adopting |
👍 on keeping these.
👍 on these names ... though I think that you should still have |
Agreed with @benjchristensen that I think we should have the following:
I don't like |
How not?
Cool, I didn't notice that before. |
Ah, I get where you're coming from now. This may be a misclassification on my part, but I've understood operators to fall into specific classification groups by their behavior.
The reason I don't believe the sampling name fits with this operator is that it isn't buffering the event then using a scheduler to emit the values. It's closer to |
Are you talking about the In any case, if the word "sample" evokes traditional signal processing sampling by a constant frequency, another candidate word is "snapshot": |
@staltz Yes, sample can "schedule" emission using another Observable, but it's not joining the sampled Observable and the "scheduler" Observable's values together. Join is. |
Alright, you convinced me. |
I think all of these have been met, or are being met by other issues. Closing. |
Proposed Change
This was brought up by @jhusain and I agree,
flatMap
isn't the easiest way to explain the operator.The proposal is to change to a structure of
[mergeStrategy][MappingStrategy]
for names:merging strategies are:
mapping strategies are:
So for example:
flatMap(x => someObservable(x))
->mergeMap(x => someObservable(x))
flatMap(Observable.just(32))
->mergeMapTo(Observable.just(32))
flatMapLatest(x => someObservable(x))
->latestMap(x => someObservable(x))
(orswitchMap(x => someObservable(x))
)a.zip(b, (a,b) => a + b)
->a.zipMap(b, (a,b) => a + b)
Observable.zipArray(a, b, c)
->Observable.zipAll(a, b, c)
a.combineLatest(b, (a, b) => a + b)
->a.combineMap(b, (a, b) => a + b)
a.combineLatest(b, (a, b) => [a, b])
->a.combineAll(b)
a.withLatestFrom(b, (a, b) => a + b)
->a.withMap(a, (a, b) => a + b)
Other questions
zip
,combineLatest
andwithLatestFrom
? which are all merge strategies... how can we fit them into this idiom? Are they different enough they don't require change?cc/ @trxcllnt
(edit: adding zip and combine) I suppose we can merge them with All defaulting to an Array.
The text was updated successfully, but these errors were encountered: