Add `@graphemes(..)`, `@bytes(..)` and `@chars(..)`
Created by: huntergoldstein
Problem: Users cannot iterate over the contents of a string easily.
Solution: Add in three new ArrayMethod
s that map from string variables to arrays:
-
@graphemes(..)
iterates over the unicode graphemes of the string as per this crate -
@bytes(..)
iterates over the UTF-8 byte sequence that corresponds to the given string -
@chars(..)
iterates over the unicode scalars of the byte sequence as perString::chars
Changes introduced by this pull request:
- Add the three above methods to
parser::shell_expand::words
- Introduce a new trait for applying a
Select
variant to an iterator DRYer
Drawbacks:
- The
SelectWithSize
trait is not optimal as it always requires the size of the iterator that is passed in; in most cases we are not dealing withExactSizeIterator
so this requires making a copy of the iterator and usingIterator::count()
. - Having
SelectWithSize::select
work likecollect
means that it is costly to map / filter / reduce after callingselect
, but I don't think this will be an issue.
Fixes: Closes #316 (closed)
State: WIP: I'm not quite sure if SelectWithSize
is the right approach. Any and all thoughts are appreciated.
Other:
- Depending on how we feel about
SelectWithSize
I want to start refactoring code that can be replaced with a similar pattern. - The alternative for
SelectWithSize
is aSelect<I>
iterator; we could implementFrom<I>
for other iterators, which would allow us to specialize the logic more efficiently (versus having a catch-all solution that).