-
Notifications
You must be signed in to change notification settings - Fork 147
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
Added complete method, just like toArray but passes first error if occurs #488
Conversation
@robertstettner Thanks for this. I have two comments.
|
@vqvu No problem. I have updated with your comments. |
I merged #487 before this, and it looks like master conflicts with the changes now (probably from the Also, I've been thinking about the name, and |
@vqvu I see your point. However, I feel that But
EDIT: maybe even |
It doesn't completely consume the source stream when there's an error. For example, _((push, next) => {
push(new Error("Error"));
push(null, 1);
push(new Error("Error2"));
push(null, _.nil);
})
.doto(_.log)
.errors((err, push) => {
_.log(err);
push(err);
})
.complete(_.log)
// This should only print the single error (though it'll happen twice).
// => [Error: Error]
// => [Error: Error] undefined Both the current and your original implementation does this. This is the only reasonable way to implement this operator. That is, we assume that the caller wants We can't use
I agree that this method is about the first argument. So shouldn't we call that out? |
ooh, I love naming problems. I had a hard time finding a close match, but It might be hard to make it a single word without there being some ambiguity though, so maybe something like |
Welcome to the party! 😄 I don't think either I'm not too happy about the verbosity of
|
I quite like EDIT: @vqvu I do see your point about |
I just had a weird idea, since the intension is to make it compatible with a callback-return pattern, maybe call it Maybe for versatility we could also have an optional |
You make a good point about the intention to convert to the Node callback pattern. I really like
Yeah. I'm not sure how we would do this and still stay in the Node callback pattern. For versatility, though, we could require users to use this operator only when there is a single value in the stream. That is, rather than forcing a stream.collect().toCallback(cb) // or
stream.take(1).toCallback(cb) // or
stream.reduce(...).toCallback(cb) // or
stream.through(customOperator()).toCallback(cb) // or simply
stream.toCallback(cb) We'd have to call it
|
I think allowing the stream to emit no values is okay, although it's not a common case, there are some libraries that call back with only an error argument. The other cases sound good, but I'm worried about introducing hard-to-detect runtime errors by requiring only one item to be in the stream. Maybe just callback with the first emitted item instead? |
That's a good point about allowing no values. I'm not too concerned about emitting errors for the other cases. There's only so many call-sites for the operator, especially since it's a consumption method, which are called much more rarely. Plus, it feels wrong to be ignoring such an obvious and easily detectable bug. Users can stick a |
Yeah, that's a fair point, I guess if the end-developer is properly testing their code it should only help and not hurt if we throw when multiple values are emitted. |
@vqvu |
I'd like to change this PR to the |
mhm, +1 to fewer methods in the library in favor of chaining for equivalent functionality |
Closing this since #493 was merged. |
This request is related to #484. I wanted to have way of consuming the stream and calling a standard callback which takes an error if occurred as the first parameter.