www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - findSplit

reply "Gecko" <hahaha internet.com> writes:
Hello,
is there a pretty way to split a range into 3 pieces, like 
findSplit, just with a predicate instead of comparing it with an 
element.

Like this :

void main() {
     import std.algorithm, std.stdio;

     auto list = [1,2,3,4,5,6,7];
     writeln(findSplit!(x => x == 3 )(list));
     //should print Tuple!(....) ([1,2], [3], [4,5,6,7])
}

findSplit accepts a predicate but it doesnt compile for me if i 
use an other function than ((a,b) => a == b).
Jul 25 2014
parent "Jakob Ovrum" <jakobovrum gmail.com> writes:
On Friday, 25 July 2014 at 18:56:44 UTC, Gecko wrote:
 findSplit accepts a predicate but it doesnt compile for me if i 
 use an other function than ((a,b) => a == b).
Not at the moment. I've been working on a patch that makes the `findSplit*` family of algorithms as powerful as `find`, including support for your use case.
Jul 25 2014