Gabriella439 / pipes

Compositional pipelines
BSD 3-Clause "New" or "Revised" License
487 stars 72 forks source link

Change takeWhile to return the failing element #145

Closed jwiegley closed 9 years ago

jwiegley commented 9 years ago

This gives pipelines a chance to hand the failing element downstream:

    runEffect $ for (each [1..10] >-> (P.takeWhile (<4) >>= yield >> cat)) $
        liftIO . Prelude.print

Otherwise, there is no way to make use of that element, neither to drop it, consume it, nor re-yield it.

Gabriella439 commented 9 years ago

I'm reluctant to change the existing function, mainly because it is a strongly breaking change. This function is commonly downstream of a Producer whose return value is () and if you change the return value of takeWhile to something other than unit then it will break existing code.

However, I would be okay with adding another function with a similar name (i.e. takeWhile' or something similar) and then implementing takeWhile in terms of this new function.

jwiegley commented 9 years ago

@Gabriel439 Yes, that's an understandable rejection. I was thinking of something like takeWhileAwait to indicate to the user that it will consume values and then produce another one. How does that sound?

Gabriella439 commented 9 years ago

How about a synonym like spanWhile?

jwiegley commented 9 years ago

@Gabriel439 Hmm.. except that a span is something I'd expect to be in pipes-group. I think maybe your original suggestion of takeWhile' is probably best.

Gabriella439 commented 9 years ago

Alright, that sounds good

jwiegley commented 9 years ago

Commit has been updated.

Gabriella439 commented 9 years ago

Thanks! :)