Skip to content
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

adding firstMap() #89

Open
chrisguttandin opened this issue Mar 24, 2021 · 2 comments
Open

adding firstMap() #89

chrisguttandin opened this issue Mar 24, 2021 · 2 comments

Comments

@chrisguttandin
Copy link
Contributor

Hi Nicholas,

what do you think about adding a firstMap() operator? I often use a pattern like this in my code:

someObservable$
    .pipe(
        first(),
        mergeMap(() => {
            // ...
        })
    )

But sometimes I end up using switchMap() or concatMap() instead of mergeMap(). I think it doesn't matter which xxxMap() operator gets used after the first() operator and it always makes me wonder if it would be easier to reason about the code if there was an operator which just hides that.

someObservable$
    .pipe(
        firstMap(() => {
            // ...
        })
    )

If you think it's a useful addition, I would be happy to provide a PR for it.

@cartant
Copy link
Owner

cartant commented Mar 25, 2021

Hmm. I'm not sure. If someone unfamiliar with firstMap were to encounter it in source, would they assume that if flattens rather than effects a higher-order observable - i.e. that it's not ...pipe(first(), map(value => /* map value to an ObservableInput */)? What if the mapped value was an array (or an iterable)? Reading it, it wouldn't be obvious that the resultant observable would emit the arrays elements rather than the array itself.

@chrisguttandin
Copy link
Contributor Author

Yes, you're right. I did not realize that the name would be misleading.

Do you have an idea for a better name. If not I'm also happy to just close this. I was just an idea.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants