Skip to content
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

Make splitting more generic #141

Merged
merged 9 commits into from
Dec 12, 2023
Merged

Make splitting more generic #141

merged 9 commits into from
Dec 12, 2023

Conversation

tcbrindle
Copy link
Owner

Rather than a pattern, split_adaptor now uses a "Splitter", a function object which, when passed a sequence, returns the bounds of the next slice.

This opens the door to potentially doing more sophisticated splitting, for example using a (CTRE?) regex or one of the standard library searchers.

At the moment, we don't publicly expose the generic Splitter interface, but this could be done in future. Rather, our existing split() overloads have been changed to use new (internal) pattern_splitter and delim_splitter implementations.

Rather than a pattern, `split_adaptor` now takes a "Splitter", a function object which, when passed a sequence, returns the bounds of the next slice.

This opens the door to potentially doing more sophisticated splitting, for example using a (CTRE?) regex or one of the standard library searchers.

At the moment, we don't publicly expose the generic Splitter interface, but this could be done in future. Rather, our existing `split()` overloads have been changed to use new (internal) `pattern_splitter` and `delim_splitter` implementations.
Copy link

codecov bot commented Dec 6, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (c2be7c5) 97.71% compared to head (3daf890) 97.98%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #141      +/-   ##
==========================================
+ Coverage   97.71%   97.98%   +0.27%     
==========================================
  Files          67       66       -1     
  Lines        2402     2380      -22     
==========================================
- Hits         2347     2332      -15     
+ Misses         55       48       -7     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

We split every time the predicate returns true, i.e.

    split("two spaces ->  <-", ::isspace)

would yield ["two", "spaces", "->", "", "<-"], with an empty sequence between the arrows.
Not sure how long this has been broken for, ooops...
If you pass equal() two sequences-of-sequences which are not directly equality comparable, but whose inner sequence types *are* comparable, then it will recursively call itself to compare the inner sequences.

This is actually pretty neat.
...and likewise, size() and usize().

These can be useful with sequences that produce rvalue subsequences, like split().
And a long old example, too
When its parent sequence is bounded, anyway
@tcbrindle tcbrindle merged commit 51fa653 into main Dec 12, 2023
27 checks passed
@tcbrindle tcbrindle deleted the pr/split_on branch January 20, 2024 12:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant