www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Variant of chunkBy that can lazily split a string on case-changes

reply Per =?UTF-8?B?Tm9yZGzDtnc=?= <per.nordlow gmail.com> writes:
Have anybody implemented a lazy iteration algorithm similar to

https://dlang.org/phobos/std_algorithm_iteration.html#chunkBy

that can group elements using a binary predicate being able to do 
to the following.

This example

     import std.ascii : isUpper, isLower;
     foreach (e; ["SomeCamelCaseName"].chunkByX!((a,b) => 
a.isUpper && b.isLower))
     {
         writeln(e);
     }

shall print

     Some
     Camel
     Case
     Name

?
Oct 27 2018
parent Per =?UTF-8?B?Tm9yZGzDtnc=?= <per.nordlow gmail.com> writes:
On Saturday, 27 October 2018 at 16:54:59 UTC, Per Nordlöw wrote:
 that can group elements using a binary predicate being able to 
 do to the following.
Oops, turns out I already had this at https://github.com/nordlow/phobos-next/blob/721374f3815db41cc213b108f81ca13ea7b93721/src/slicing.d#L12 This is a less generic solution though with a unary predicate but it works in my case. Still looking for a more general solution.
Oct 27 2018