Re: Transform a sorted range to a range of ranges of equal elements

2014-12-01 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Dec 02, 2014 at 01:03:12AM +, Tobias Pankrath via Digitalmars-d-learn wrote: > > > >Phobos git HEAD has a new range adaptor called groupBy that does what > >you want: > > > > assert([1,1,2,2,2,3,4,4].groupBy!((a)=>a).equal( > > [[1,1], [2,2,2], [3], [4,4]] > > )) >

Re: Transform a sorted range to a range of ranges of equal elements

2014-12-01 Thread Tobias Pankrath via Digitalmars-d-learn
Phobos git HEAD has a new range adaptor called groupBy that does what you want: assert([1,1,2,2,2,3,4,4].groupBy!((a)=>a).equal( [[1,1], [2,2,2], [3], [4,4]] )) T Thanks! I wonder if this works with all input ranges. As I see it, every implementation will ha

Re: Transform a sorted range to a range of ranges of equal elements

2014-12-01 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Dec 01, 2014 at 06:37:13PM +, Tobias Pankrath via Digitalmars-d-learn wrote: > Basically I need std.algorithm.uniq or std.algorithm.group, but > instead of a single element or an element and a number I want ranges > that each contain consecutive elements considered equal. > > Example:

Transform a sorted range to a range of ranges of equal elements

2014-12-01 Thread Tobias Pankrath via Digitalmars-d-learn
Basically I need std.algorithm.uniq or std.algorithm.group, but instead of a single element or an element and a number I want ranges that each contain consecutive elements considered equal. Example: [1,1, 2,2,2,3,4,4] -> [1, 1], [2,2,2], [3], [4,4]. Let's call this uniqRange. This way std.algo