Name a phobos function!

H. S. Teoh hsteoh at quickfur.ath.cx
Mon Mar 15 17:09:56 UTC 2021


On Mon, Mar 15, 2021 at 01:35:24PM +0000, Dukc via Digitalmars-d wrote:
> I am currently authoring a pull request to Phobos, here:
> https://github.com/dlang/phobos/pull/7794. I'm trying to get a new
> function added. Currently it's named `splitBy`, and it's behaviour is
> probably best described by documentation:
> 
> -------------------------
> Splits a forward range into subranges in places determined by a binary
> predicate. When iterating, one element of `r` is compared with `pred`
> to the next element. If `pred` return true, a new subrange is started
> for the next element. Otherwise, they are part of the same subrange.
> If the elements are compared with an inequality (!=) operator,
> consider $(LREF chunkBy) instead, as it's likely faster to execute.
[...]

Thanks for doing this!  I've been feeling a need for something like this
for a while now, but just haven't gotten around to implementing it
myself.

IMO, `splitBy` and `chunkBy` are too similar, yet with quite different
(almost opposite) semantics.  I propose `splitWhen`, since the range is
split when the predicate returns true.


On a more general note, I wonder if there's an overarching or unifying
theme between the current range-splitting functions, of which we have
quite a variety:

- std.range.chunks
- std.algorithm.group
- std.algorithm.splitter
- std.algorithm.chunkBy (no thanks to yours truly ;-))
- Now being proposed: splitBy / splitWhen

It would be nice to have some uniformity across these range-splitting
functions so that their individual roles are clearer.  Currently, a new
user looking at the above list would likely be left scratching his head
as to what the difference between these functions are, and when to use
which.  It would be nice if there was a way to unify them under a single
umbrella (or two); or if not, at the very least have some sort of
logical system to the naming so that their individual roles are clearly
situated in a coherent scheme, rather than the current haphazard mess.


T

-- 
The best compiler is between your ears. -- Michael Abrash


More information about the Digitalmars-d mailing list