Closed abelbraaksma closed 8 months ago
@bartelink, in case you have some time, I can use an extra pair of eyes here (meanwhile, I'll fix the failing tests).
@bartelink thanks for the extensive review, much appreciated! I applied all your comments, insofar they were still applicable after some other changes.
Almost forgot to update the readmes and release notes, oops!
re that use case... there's a double iteration in the error case and its actually the last item returned that would be the failing one but if there was only one item in the list then that last item would be valid
the example you have feels more like you are picturing a scan until or something
if you want to skip while some condition and then skip one more, that's not going to help you show the extra one you skipped
is there some partition function of some kind that this might make sense as? such a thing could split a list into 3 over some pivot or something?
for takeWhile
, I can explain the use case more easily...
I am searching until I find something
if I reach the end of the list, then that's fine too
but I also want the final item that I was searching for
so its a 'scanUntil' semantic, which AsyncSeq/Eirik happened to call takeWhileInclusive
as its literally TakeWhile but includes the last item
It does not particularly lend itself to showing the failing one, as the final item can either simply be the last item in the list or it can be the item that defines the place where we abort the search
In completely concrete terms, I'm searching backward through a list of events until I meet either a) a Snapshot b) a Reset event or c) the end of the list Once I have that part of the list, I can fold/reduce from there forward
Oh yeah, I deleted my "use case" shortly after posting it. But here's one:
A*B;C*D;...
, but without the tuples. That is, every item is a pair, but it is a flat sequenceskipWhileInclusive
Yep, a bit contrived, for sure. I'm sure other use cases will come up, or not...
so you have a list with pairs of items and when you see the first one, you want to skip its partner that's not very general though - what if the pairs that are not pairs that you are explaining as pairs were triples?
ultimately the reason why takeWhileInclusive does make sense is that it's all about the single item being tested - do you want the final one or not
also not wanting the one after that you're not even going to look at before discarding implicitly is not a logical inverse of that
(See above about windowing/partitioning/having a pivot item - SkipWhileInclusive is ultimately very baroque and I'm not seeing any real example - maybe if you can find one in the wild (or any prior art / discussion of this logical duality), that would help?)
maybe if you can find one in the wild (or any prior art / discussion of this logical duality), that would help?)
Yeah, that's gonna be hard. Just like with takeWhileInclusive
, which I cannot find "in the wild" on a quick search, I doubt I can find its logical inverse, skipWhileInclusive
. Let's keep it in, as not doing so would raise questions on takeWhileInclusive
. If we want the one, we should want the other as well (parity, orthogonality, principle of least surprise etc).
Some things I missed from review comments go in #220.
Fixes #130 (edit: see also #235)
Part of the push for implementing low-hanging from as listed in #208. Implements the following signatures:
Note that
inclusive
here means that it skips at least one item (i.e., the modifier applies to the action of skipping). This is analogous to howtakeWhileInclusive
etc work.Some explanation may be warranted for future reference. Here's a truth table of
1..10
and a filter function offilter x = x < 5
for bothinclusive
andnon-inclusive
skip functions (also applies totake
functions):skipWhile
skipWhileInclusive
TODO list:
TaskSeq.skipWhile
TaskSeq.skipWhileAsync
TaskSeq.skipWhileInclusive
TaskSeq.skipWhileInclusiveAsync