>>> 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
>>> sequenceA_ [print "Hello", print "world", print "!"] "Hello" "world" "!"
>>> 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
>>> "GHC" `isSubsequenceOf` "The Glorious Haskell Compiler" True
>>> ['a','d'..'z'] `isSubsequenceOf` ['a'..'z'] True
>>> [1..10] `isSubsequenceOf` [10,9..0] FalseFor the result to be True, the first list must be finite; for the result to be False, the second list must be finite:
>>> [0,2..10] `isSubsequenceOf` [0..] True
>>> [0..] `isSubsequenceOf` [0,2..10] False
>>> [0,2..] `isSubsequenceOf` [0..] * Hangs forever*
>>> take 1 (subsequences undefined) [[]] >>> take 2 (subsequences ('a' : undefined)) ["","a"]
>>> subsequences "abc" ["","a","b","ab","c","ac","bc","abc"]This function is productive on infinite inputs:
>>> take 8 $ subsequences ['a'..] ["","a","b","ab","c","ac","bc","abc"]