New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
_.unzip unit tests not testing documented usage. #1190
Comments
Looks like it's documented in the source one way and in the documentation another: // The inverse operation to `_.zip`. If given an array of pairs it
// returns an array of the paired elements split into two left and
// right element arrays, if given an array of triples it returns a
// three element array and so on. For example, `_.unzip` given
// `[['a',1],['b',2],['c',3]]` returns the array
// [['a','b','c'],[1,2,3]]. |
The operation: _.unzip(_.zip(['moe', 'larry'], [30, 40], [true, false]));
// produces [[["moe",30,true]],[["larry",40,false]]]
// instead of [['moe', 'larry'], [30, 40], [true, false]] |
Looks like this change was introduced in the actual 1.5.0 commit :/ |
Not broke, changed. Updated the comment above. |
Why the last minute change in functionality? |
It's a bit of a bummer that zip and unzip aren't inverse functions. I wish there were some equivalent of Ruby's splat operator to deal with having to do something like this: res = _.zip(['moe', 'larry'], [30, 40], [true, false]);
_.unzip(res[0], res[1]); Though, none of the other array functions take multiple arguments and return an array of results, on the other hand. |
Because this way, they're parallel. Previously, zip took individual arrays as arguments, and unzip took an array of (somewhat carefully constructed) arrays. Previously, they weren't inverse functions, because you couldn't have passed the output of unzip directly into zip. This way, they both allow input as individual arguments (as you might want to write it), and can be |
Wait, now _.zip(['moe', 'larry', 'curly'], [30, 40, 50], [true, false, false]);
// => [["moe", 30, true], ["larry", 40, false], ["curly", 50, false]]
_.unzip(['moe', 'larry', 'curly'], [30, 40, 50], [true, false, false]);
// => [["moe", 30, true], ["larry", 40, false], ["curly", 50, false]] The docs for I think it would have made more sense to keep it the way it was originally implemented, possibly extending |
Quite so. I guess that the original proposal to add unzip was a bit foolish from the get-go. Ruby, for example, only has a |
Cool. I'm going to go with making var expected = [['moe', 'larry'], [30, 40]];
_.unzip(_.zip(_.unzip(_.zip(expected))));
// => [['moe', 'larry'], [30, 40]] |
The
_.unzip
unit tests are testing onlywhich is not the documented usage.
The text was updated successfully, but these errors were encountered: