From c7dbebe0df36ca83352dba28c6e0177008bf84ad Mon Sep 17 00:00:00 2001 From: RazvanN7 Date: Thu, 24 Aug 2017 10:05:30 +0300 Subject: [PATCH] Fix Issue 6004 - std.range.unzip() --- std/range/package.d | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/std/range/package.d b/std/range/package.d index e50cc62cc..25a8806b9 100644 --- a/std/range/package.d +++ b/std/range/package.d @@ -6282,7 +6282,8 @@ FrontTransversal!(RangeOfRanges, opt) frontTransversal( /** Given a range of ranges, iterate transversally through the - `n`th element of each of the enclosed ranges. + `n`th element of each of the enclosed ranges. This function + is similar to `unzip` in other languages. Params: opt = Controls the assumptions the function makes about the lengths @@ -6518,7 +6519,17 @@ Transversal!(RangeOfRanges, opt) transversal x[0] = [1, 2]; x[1] = [3, 4]; auto ror = transversal(x, 1); - assert(equal(ror, [ 2, 4 ][])); + assert(equal(ror, [ 2, 4 ])); +} + +/// The following code does a full unzip +@safe unittest +{ + import std.algorithm.comparison : equal; + import std.algorithm.iteration : map; + int[][] y = [[1, 2, 3], [4, 5, 6]]; + auto z = y.front.walkLength.iota.map!(i => transversal(y, i)); + assert(equal!equal(z, [[1, 4], [2, 5], [3, 6]])); } @safe unittest