Skip to content
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

Suggestion: deprecate the unzip function in favor of the zip function #3407

Closed
ayame113 opened this issue May 26, 2023 · 3 comments
Closed

Comments

@ayame113
Copy link
Contributor

Is your feature request related to a problem? Please describe.

The current zip() is upward compatible with unzip(). Both just transpose a 2D array.

import { zip } from "https://deno.land/[email protected]/collections/zip.ts";
import { unzip } from "https://deno.land/[email protected]/collections/unzip.ts";

const target = [[0, "a"], [1, "b"]];

const zipped = zip(...target);
console.log(zipped); // [ [ 0, 1 ], [ "a", "b" ] ]

const unzipped = unzip(target);
console.log(unzipped); // [ [ 0, 1 ], [ "a", "b" ] ]

Describe the solution you'd like

How about deprecating unzip in favor of zip?

Describe alternatives you've considered

The only difference between zip and unzip is that when they receive multiple arrays of different lengths, they align to the shortest or the longest.

import { zip } from "https://deno.land/[email protected]/collections/zip.ts";
import { unzip } from "https://deno.land/[email protected]/collections/unzip.ts";

const target = [[0, "a"], [1]];

const zipped = zip(...target);
console.log(zipped); // [ [ 0, 1 ] ]

const unzipped = unzip(target);
console.log(unzipped); // [ [ 0, 1 ], [ "a", undefined ] ]

In Python, there is no unzip function, but instead there is a itertools.zip_longest function. How about deprecating unzip, adding zipLongest and resolving #1203?

@denizdogan
Copy link
Contributor

I think zip and unzip should be left separate even if they'd end up pointing at the same function, because they are different conceptually. zip(*zipped_list) doesn't read "unzip" to me, and probably never will, having worked with Python for many years. I see no reason why deno_std would take any inspiration from Python of all languages.

@iuioiua
Copy link
Contributor

iuioiua commented Dec 7, 2023

@ayame113, do you still have this opinion? I'm slightly in favour of keeping unzip() as it is. Though, I'm mostly impartial.

@ayame113
Copy link
Contributor Author

ayame113 commented Dec 9, 2023

deno_std's zip function takes a variable length argument instead of two arguments. There is a big difference between zip and unzip when the zip function takes 2 arguments, but not much difference between them when the zip function takes 3 or more arguments. For this reason, I thought it would be possible to use Python's naming conventions.
That being said, I don't have a strong opinion on this either, so feel free to leave the unzip naming as is. Let's close this issue. 👍

@ayame113 ayame113 closed this as completed Dec 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants