Splitting a sequence using a binary predicate on adjacent elements

Andrea Fontana nospam at example.com
Wed Oct 18 07:01:19 UTC 2017


On Wednesday, 18 October 2017 at 06:45:37 UTC, Nordlöw wrote:
> On Tuesday, 17 October 2017 at 14:15:02 UTC, Andrea Fontana 
> wrote:
>> auto splitBy(alias F, R)(R range)
>
> Because of lazyness shouldn't it be named something with 
> splitter, say splitterBy, instead?

Yes but I think it is something more similar to chunkBy, but 
chunkBy says that "predicate must be an equivalence relation, 
that is, it must be reflexive (pred(x,x) is always true), 
symmetric (pred(x,y) == pred(y,x)), and transitive (pred(x,y) && 
pred(y,z) implies pred(x,z)). If this is not the case, the range 
returned by chunkBy may assert at runtime or behave erratically."

If you try to use your data with chunkBy!"a != b+1", it does not 
work, as expected.

I think that my implementation could superseed the current one, 
since it seems to work in a more generic way.

Andrea


More information about the Digitalmars-d-learn mailing list