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

Tobias Pankrath via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon Dec 1 17:03:12 PST 2014


>
> 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 have to iterate the original range
twice (if fully consumed). One iteration by the subranges and one
to move subrange range forward. It only skimmed the code, but I'd 
thought that would at least require forward ranges or a buffer.


More information about the Digitalmars-d-learn mailing list