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
add pipeline-async functions #26
Comments
Anyone ? |
In the above code, if 'f' were an async function then the variable 'mapResult' would be undefined. In fact, even if 'f' was a synchronous function, an error will be thrown when csp.take(mapResult) gets executed. |
@discreteinfinity What I want is a function that take one input channel and apply the synchronous function "f" to each value from the input channel. This is the equivalent of flatMap in other FRP framework like Bacon.js |
@zeroware Sorry, I was at a work week last week and today been catching up on work stuff. I will respond more thoroughly later tonight or tomorrow. I haven't fully read this issue, but a flatMap equivalent would be the var ch = chan(1, t.mapcat(foo)); Reading your comment above, that isn't the same though. It will only merge in concrete arrays, not channels. If you want that, you should look at the higher-order These APIs will probably be slightly changed soon to make things as simple/uniform as possible, but the above should work. |
@jlongster Thanks for answering. I don't know if mapcat can do it. /**
* Return a channel which contains the HTTP response of GET request to url
*
* @param {string} url
* @return {Channel}
*/
var getUrlContent = function(url) {
//...
};
var chan = csp.chan();
yield csp.put(chan, "http://example.org");
yield csp.put(chan, "http://example.org/foo");
var responseChan = flatMap(chan, getUrlContent);
// Response chan will be filled with HTTP responses from urls contained in input channel. |
The current functions cannot do it (not directly). |
@ubolonton Thanks , I looked at core.async lib and pipeline-async is what i'm looking for. |
@zeroware Sorry, I guess didn't quite understand exactly how flatMap worked but seeing the spec for pipeline-async has made things clearer for me. Anyways, Im excited to hear that something like pipeline-async may be making its way into js-csp ! |
Initial pipeline implementation : #28 |
I merged the pipeline implementation. We just need some docs/examples now. |
I'm trying to apply an async function to every value of one channel.
In FRP this operation is typically called flatMap.
The function takes a function which return a chan.
Here is a draft of what it may look like :
Is there any other way to compose existing function to produce this kind of result ?
EDIT : I realized that this implementation is closer to flatMapConcat than flatMap.
The text was updated successfully, but these errors were encountered: