vitaly-t / iter-ops

Basic operations on iterables
https://vitaly-t.github.io/iter-ops
MIT License
136 stars 5 forks source link

start vs stop logic inconsistency #193

Closed vitaly-t closed 1 year ago

vitaly-t commented 1 year ago

We may have a bit of issue (or not) with the inconsistency: start logic is inclusive, while stop is exclusive, i.e. we start from the element that passes the predicate, but we stop with the element that's prior to the predicate that passed.

Should they not be both inclusive or exclusive?

@RebeccaStevens What do you think?

vitaly-t commented 1 year ago

I've tried to compare the logic to RXJS (where it uses a predicate):

So that doesn't help much, though if we follow their logic in the Recipes, then it is consistent with how we do it:

vitaly-t commented 1 year ago

The problem that I'm seeing now is linguistic. It makes perfect sense why skipWhile logic produces inclusive result, and why takeWhile produces exclusive result. But with the start and stop operators it is absolutely not clear, and you can assume it either way.

This brings the idea of adding skipWhile + takeWhile, and retiring start and stop operators.

vitaly-t commented 1 year ago

new operators have been added, and now in master:

vitaly-t commented 1 year ago

v2.4.0 now has the new operators.

The old operators will be removed in v3.0.0, as it will be a breaking change.

vitaly-t commented 1 year ago

TODO: Need to revisit the inclusive/exclusive logic added by skipUntil and takeUntil, to see if they are needed.

UPDATE

Here's what I found, after many tests and analysis...

The until logic is supposed to complete the scope by reversing that:

Then we would have a complete logical range. ☝️

CONCLUSION

We do need to add inclusive takeUntil and exclusive skipUntil, to complete our logical range. 🔖

vitaly-t commented 1 year ago

I did not feel sure about this, so I have posted a question.

vitaly-t commented 1 year ago

Looks like my assumption was correct after all, and until must be treated as check after, which makes takeUntil inclusive, and skipUntil exclusive.

vitaly-t commented 1 year ago

New operator takeUntil merged into the master.

vitaly-t commented 1 year ago

New operator skipUntil merged into the master.

vitaly-t commented 1 year ago

v2.5.0-beta.0 released with all 4 new operators.

vitaly-t commented 1 year ago

v2.5.0 release completed this task.