:: [[a]] -> [[a]] package:ghc-internal

The transpose function transposes the rows and columns of its argument.

Laziness

transpose is lazy in its elements
>>> take 1 (transpose ['a' : undefined, 'b' : undefined])
["ab"]

Examples

>>> transpose [[1,2,3],[4,5,6]]
[[1,4],[2,5],[3,6]]
If some of the rows are shorter than the following rows, their elements are skipped:
>>> transpose [[10,11],[20],[],[30,31,32]]
[[10,20,30],[11,31],[32]]
For this reason the outer list must be finite; otherwise transpose hangs:
>>> transpose (repeat [])
* Hangs forever *
Evaluate each action in the sequence from left to right, and collect the results.
This function is only used in Quote when desugaring brackets. This is not necessary for the user, who can use the ordinary return and (>>=) operations.
Evaluate each action in the structure from left to right, and collect the results. For a version that ignores the results see sequenceA_.

Examples

Basic usage: For the first two examples we show sequenceA fully evaluating a a structure and collecting the results.
>>> sequenceA [Just 1, Just 2, Just 3]
Just [1,2,3]
>>> sequenceA [Right 1, Right 2, Right 3]
Right [1,2,3]
The next two example show Nothing and Just will short circuit the resulting structure if present in the input. For more context, check the Traversable instances for Either and Maybe.
>>> sequenceA [Just 1, Just 2, Just 3, Nothing]
Nothing
>>> sequenceA [Right 1, Right 2, Right 3, Left 4]
Left 4
Evaluate each monadic action in the structure from left to right, and collect the results. For a version that ignores the results see sequence_.

Examples

Basic usage: The first two examples are instances where the input and and output of sequence are isomorphic.
>>> sequence $ Right [1,2,3,4]
[Right 1,Right 2,Right 3,Right 4]
>>> sequence $ [Right 1,Right 2,Right 3,Right 4]
Right [1,2,3,4]
The following examples demonstrate short circuit behavior for sequence.
>>> sequence $ Left [1,2,3,4]
Left [1,2,3,4]
>>> sequence $ [Left 0, Right 1,Right 2,Right 3,Right 4]
Left 0