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

Can't map function to errors only so that they remain errors. #670

Open
mrehayden1 opened this issue Jul 18, 2016 · 1 comment
Open

Can't map function to errors only so that they remain errors. #670

mrehayden1 opened this issue Jul 18, 2016 · 1 comment

Comments

@mrehayden1
Copy link

mrehayden1 commented Jul 18, 2016

Could we have a method on Observable that will map over error values only but not feed them into the value stream?

I've needed this a number of times and come up with this extension using a modified version of mapError(), which I have called mapErrors().

Bacon.Observable.prototype.mapErrors = function(f) {
    return withDesc(new Bacon.Desc(this, "mapError", [f]), this.withHandler(function (event) {
        if (event.isError()) {
            return this.push(new Bacon.Error(f(event.error)));
        } else {
            return this.push(event);
        }
    }));
};

This can't use the function construction features because it's all hidden away in the Bacon module so it would great to see it included in the distribution.

@raimohanska
Copy link
Contributor

There's indeed a flatMapError method available that you can use to this effect. Unfortunately it doesn't currently support function construction from arguments...

Maybe we should do 2 things:

  1. introduce flatMapEvent, that would allow you to flatmap any event (value, error, end) into any sequence of events
  2. publish the function construction API to make it usable for custom functions
  3. fix flatMapError to support function construction

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