What is the proper name for a zip-like method that "collapses" a list of lists?

Given a list of lists, e.g. ((abcd) (efgh) (ijkl) (mnop) (qrst)) , I would like to write a conversion to a new list of lists consisting of the first element from each list, after the second element from each list, etc. d. (in my example, the result of this will be ((aeimq) (bfjnr) (cgkos) (dhlpt)) ).

Does this operation have a different name besides zip ? If so, what is this name?

+4
source share
3 answers

The best word for him is probably transpose .

Your list of lists can be considered as a matrix, and this is a matrix transfer.

+7
source

In Haskell, this function is called transpose .

+6
source

For such questions, I usually turn to Hoogle for inspiration. After we parse the type signature for your function, Hoogle tells us that haskell uses both transpose and sequence to perform this conversion (although you need to squint a bit at the sequence, note that this means the same for the list monad).

Transpose looks better than a list operation, but the sequence makes a lot of sense when working with other monads.

+4
source

Source: https://habr.com/ru/post/1391939/


All Articles