Re: Adjacent Pairs Range

2015-09-15 Thread Sebastiaan Koppe via Digitalmars-d-learn
On Monday, 14 September 2015 at 10:45:52 UTC, Per Nordlöw wrote: On Monday, 14 September 2015 at 05:37:05 UTC, Sebastiaan Koppe wrote: What about using zip and a slice? Slicing requires a RandomAccessRange (Array). This is too restrictive. We want to change operations such as adjacentTuples

Re: Adjacent Pairs Range

2015-09-14 Thread Per Nordlöw via Digitalmars-d-learn
On Monday, 14 September 2015 at 05:37:05 UTC, Sebastiaan Koppe wrote: What about using zip and a slice? Slicing requires a RandomAccessRange (Array). This is too restrictive. We want to change operations such as adjacentTuples with for example map and reduce without the need for temporary

Re: Adjacent Pairs Range

2015-09-14 Thread Per Nordlöw via Digitalmars-d-learn
On Monday, 14 September 2015 at 10:45:52 UTC, Per Nordlöw wrote: restrictive. We want to change operations such as Correction: We want to *chain* operations such as...

Re: Adjacent Pairs Range

2015-09-13 Thread Nordlöw via Digitalmars-d-learn
On Sunday, 13 September 2015 at 01:49:56 UTC, deed wrote: zip(arr[0 .. $-1], arr[1 .. $]) ? Assumes arrays. Better is zip(arr.dropOne, arr)

Re: Adjacent Pairs Range

2015-09-13 Thread Sebastiaan Koppe via Digitalmars-d-learn
On Saturday, 12 September 2015 at 10:17:19 UTC, Nordlöw wrote: How do I most elegantly iterate all the adjacent pairs in an `InputRange` using Phobos? Something like [1,2,3,4] => [(1,2), (2,3), (3,4)] What about using zip and a slice? ``` void main() { auto a = [1,2,3,4];

Re: Adjacent Pairs Range

2015-09-12 Thread deed via Digitalmars-d-learn
On Saturday, 12 September 2015 at 10:17:19 UTC, Nordlöw wrote: How do I most elegantly iterate all the adjacent pairs in an `InputRange` using Phobos? Something like [1,2,3,4] => [(1,2), (2,3), (3,4)] Why not just: zip(arr[0 .. $-1], arr[1 .. $]) ?

Re: Adjacent Pairs Range

2015-09-12 Thread Nordlöw
On Saturday, 12 September 2015 at 10:35:41 UTC, Bahman Movaqar wrote: On 09/12/2015 02:47 PM, "Nordlöw" wrote: How do I most elegantly iterate all the adjacent pairs in an `InputRange` using Phobos? Something like [1,2,3,4] => [(1,2), (2,3), (3,4)] That's call `collate`ing IIRC. A

Re: Adjacent Pairs Range

2015-09-12 Thread Bahman Movaqar via Digitalmars-d-learn
On 09/12/2015 02:47 PM, "Nordlöw" wrote: > How do I most elegantly iterate all the adjacent pairs in an > `InputRange` using Phobos? > > Something like > > [1,2,3,4] => [(1,2), (2,3), (3,4)] That's call `collate`ing IIRC. A quick solution would be using `std.range.transposed`: auto a =

Re: Adjacent Pairs Range

2015-09-12 Thread Bahman Movaqar via Digitalmars-d-learn
On 09/12/2015 04:04 PM, Bahman Movaqar wrote: > Oops! Here's one using only `InputRange` interface: I believe I need to warn you that I'm just learning D; so take my solution at your own risk :-) -- Bahman Movaqar

Re: Adjacent Pairs Range

2015-09-12 Thread Bahman Movaqar via Digitalmars-d-learn
On 09/12/2015 03:09 PM, "Nordlöw" wrote: > InputRange please, not RandomAccessRanges ;) Oops! Here's one using only `InputRange` interface: T[][] collate(T)(T[] a) { alias CollateResult = Tuple!(T[][], "result", T, "tlHd"); CollateResult _collate(CollateResult collres)

Re: Adjacent Pairs Range

2015-09-12 Thread Nordlöw
On Saturday, 12 September 2015 at 11:34:03 UTC, Bahman Movaqar wrote: On 09/12/2015 03:09 PM, "Nordlöw" wrote: InputRange please, not RandomAccessRanges ;) Oops! Here's one using only `InputRange` interface: I wrote my own as adjacentTuples and adjacentPairs:

Re: Adjacent Pairs Range

2015-09-12 Thread Nordlöw
On Saturday, 12 September 2015 at 11:46:55 UTC, Nordlöw wrote: I wrote my own as adjacentTuples and adjacentPairs: https://github.com/nordlow/justd/blob/master/range_ex.d#L702 Note: No yet extended to N > 2. An alternative naming would be overlappingTuples/Pairs. Should this go into Phobos?