List package:base

Operations on lists.
The List data type and its operations
(list p) parses a list of things parsed by p, using the usual square-bracket syntax.
The listToMaybe function returns Nothing on an empty list or Just a where a is the first element of the list.

Examples

Basic usage:
>>> listToMaybe []
Nothing
>>> listToMaybe [9]
Just 9
>>> listToMaybe [1,2,3]
Just 1
Composing maybeToList with listToMaybe should be the identity on singleton/empty lists:
>>> maybeToList $ listToMaybe [5]
[5]

>>> maybeToList $ listToMaybe []
[]
But not on lists with more than one element:
>>> maybeToList $ listToMaybe [1,2,3]
[1]
Construct an array from a pair of bounds and a list of values in index order.
Returns an array of the threads started by the program. Note that this threads which have finished execution may or may not be present in this list, depending upon whether they have been collected by the garbage collector.
List the Haskell threads of the current process.
The method readList is provided to allow the programmer to give a specialised way of parsing lists of values. For example, this is used by the predefined Read instance of the Char type, where values of type String are expected to use double quotes, rather than square brackets.
The method showList is provided to allow the programmer to give a specialised way of showing lists of values. For example, this is used by the predefined Show instance of the Char type, where values of type String should be shown in double quotes, rather than between square brackets.
The maybeToList function returns an empty list when given Nothing or a singleton list when given Just.

Examples

Basic usage:
>>> 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
Lists, but with an Applicative functor based on zipping.

Examples

In contrast to the Applicative for List:
>>> (+) <$> [1, 2, 3] <*> [4, 5, 6]
[5,6,7,6,7,8,7,8,9]
The Applicative instance of ZipList applies the operation by pairing up the elements, analogous to zipWithN
>>> (+) <$> ZipList [1, 2, 3] <*> ZipList [4, 5, 6]
ZipList {getZipList = [5,7,9]}
>>> (,,,) <$> ZipList [1, 2] <*> ZipList [3, 4] <*> ZipList [5, 6] <*> ZipList [7, 8]
ZipList {getZipList = [(1,3,5,7),(2,4,6,8)]}
>>> ZipList [(+1), (^2), (/ 2)] <*> ZipList [5, 5, 5]
ZipList {getZipList = [6.0,25.0,2.5]}
Write an entire list of items to a Chan.
Collects the list of elements of a structure, from left to right.

Examples

Basic usage:
>>> biList (18, 42)
[18,42]
>>> biList (Left 18)
[18]
List of elements of a structure, from left to right. If the entire list is intended to be reduced via a fold, just fold the structure directly bypassing the list.

Examples

Basic usage:
>>> 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]
readList function for an application of the type constructor based on readsPrec and readList functions for the argument type. The default implementation using standard list syntax is correct for most types.
readList function for an application of the type constructor based on readsPrec and readList functions for the argument types. The default implementation using standard list syntax is correct for most types.
A possible replacement definition for the liftReadList2 method. This is only needed for Read2 instances where liftReadListPrec2 isn't defined as liftReadListPrec2Default.
A possible replacement definition for the liftReadList method. This is only needed for Read1 instances where liftReadListPrec isn't defined as liftReadListPrecDefault.
readListPrec function for an application of the type constructor based on readPrec and readListPrec functions for the argument type. The default definition uses liftReadList. Instances that define liftReadPrec should also define liftReadListPrec as liftReadListPrecDefault.
readListPrec function for an application of the type constructor based on readPrec and readListPrec functions for the argument types. The default definition uses liftReadList2. Instances that define liftReadPrec2 should also define liftReadListPrec2 as liftReadListPrec2Default.
A possible replacement definition for the liftReadListPrec2 method, defined using liftReadPrec2.
A possible replacement definition for the liftReadListPrec method, defined using liftReadPrec.
showList function for an application of the type constructor based on showsPrec and showList functions for the argument type. The default implementation using standard list syntax is correct for most types.