unzip is applied zip

Today I discovered that to make an arbitrary arity version of SRFI-1‘s unzip1, unzip2 etc, this works:

And, since zip is just:

This means that this works:

unzip is applied zip.

Apparently.

SRFI-1‘s unzip1, unzip2 etc

dpercy points out that it works because it’s a matrix transpose.

Basically it flips a matrix like this

along the NW-SE diagonal, into

That should make it clear that this is self-reversible.

The apply is because zip takes vals and returns a list, unzip takes a list and returns vals. But that’s just a grotesque artifact of history. If zip took a list and returned a list, or if it took vals and returned vals, unzip would be zip.

If this was zip, without the vararg dot:

It would just be self-reversing. (compose zip* zip*) is an expensive shallow copy.

Proxied content from gemini://idiomdrottning.org/unzip-is-applied-zip (external content)

Gemini request details:

Original URL
gemini://idiomdrottning.org/unzip-is-applied-zip
Status code
Success
Meta
text/gemini; lang=en
Proxied by
kineto

Be advised that no attempt was made to verify the remote SSL certificate.