>>> toList Nothing []
>>> toList (Just 42) [42]
>>> toList (Left "foo") []
>>> toList (Node (Leaf 5) 17 (Node Empty 12 (Leaf 8))) [5,17,12,8]For lists, toList is the identity:
>>> toList [1, 2, 3] [1,2,3]
>>> maybeToList (Just 7) [7]
>>> maybeToList Nothing []One can use maybeToList to avoid pattern matching when combined with a function that (safely) works on lists:
>>> import GHC.Internal.Text.Read ( readMaybe ) >>> sum $ maybeToList (readMaybe "3") 3 >>> sum $ maybeToList (readMaybe "") 0