fsprojects / FSharp.Control.TaskSeq

A computation expression and module for seamless working with IAsyncEnumerable<'T> as if it is just another sequence
MIT License
93 stars 8 forks source link

Implement `TaskSeq.takeUntil`, `takeUntilAsync`, `takeUntilInclusive` and `takeUntilInclusiveAsync` #183

Closed abelbraaksma closed 11 months ago

abelbraaksma commented 1 year ago

This partially fixes #130.

These are basically the counterparts to takeWhile. This implements:

abelbraaksma commented 1 year ago

If both are to be retained, I wonder whether there's a way to do the tests to make it clear that one is the same as the other with a flipped condition?

Good point. I may consider updating this using such tests instead.

To the point of retaining or not. I have always missed a takeUntil in seq. The reason I also have the takeUntilInclusive is mainly because of your suggestion on takeWhile and posts like these: https://stackoverflow.com/questions/12562327/how-to-do-seq-takewhile-one-item-in-f.

But I like the suggestion of overloading instead. That's probably a better way to go.

abelbraaksma commented 1 year ago

PS: all suggestions have been applied to #136, it was by accident that this PR included those changes as well. I will rebase.

abelbraaksma commented 1 year ago

Ok, rebased this such that it is now properly based off of main instead. See for the doc-comment changes that I applied from your review comments: #136 (/cc @bartelink).

bartelink commented 1 year ago

Apologies for not paying attention to your responses on my comments as I made them Sounds like we are on the same page The final one alluding to Async.Parallel is the crux of it all I need to be afk for most of the rest of the day now (and am travelling later this week so will have simialrly patchy responsiveness) but should hopefully be able to fit in responding to your responses and re-reviewing later on

abelbraaksma commented 1 year ago

Awesome! Much appreciated! :)

abelbraaksma commented 11 months ago

I'm gonna kill this one off. The main use-case would be that it isn't trivial to write takeUntil through takeWhile, and this would help users write clearer code. Another use-case would be that if takeUntil is needed and you would write takeWhile (f >> not) this would not perform as well, however that issue is not resolved here.

We can always revisit once we have sorted out the other low-hanging fruit.