Haskell Language Flattening a Foldable structure into a list


Example

toList flattens a Foldable structure t a into a list of as.

ghci> toList [7, 2, 9]  -- t ~ []
[7, 2, 9]
ghci> toList (Right 'a')  -- t ~ Either e
"a"
ghci> toList (Left "foo")  -- t ~ Either String
[]
ghci> toList (3, True)  -- t ~ (,) Int
[True]

toList is defined as being equivalent to:

class Foldable t where
    -- ...
    toList :: t a -> [a]
    toList = foldr (:) []