Portability | Requires STM |
---|---|

Maintainer | joeyadams3.14159@gmail.com |

Safe Haskell | Safe-Infered |

This module uses many names from Prelude, so consider importing it qualified:

import Data.STM.TList (TList) import qualified Data.STM.TList as TList

- type TList a = TVar (TCell a)
- data TCell a
- empty :: STM (TList a)
- emptyIO :: IO (TList a)
- cons :: a -> TList a -> STM (TList a)
- append :: TList a -> a -> STM (TList a)
- appendList :: TList a -> [a] -> STM (TList a)
- fromList :: [a] -> STM (TList a, TList a)
- uncons :: STM b -> (a -> TList a -> STM b) -> TList a -> STM b
- null :: TList a -> STM Bool
- drop :: Int -> TList a -> STM (TList a)
- end :: TList a -> STM (TList a)
- length :: TList a -> STM Int
- foldl' :: (a -> b -> a) -> a -> TList b -> STM a
- toList :: TList a -> STM [a]

# The TList type

# Construction

cons :: a -> TList a -> STM (TList a)Source

*O(1)*. Prepend an item to the list, returning the new beginning of the
list.

append :: TList a -> a -> STM (TList a)Source

*O(1)*. Append an item to the list, returning the new write end.

The `TList`

normally points to a `TNil`

, a "hole" into which the next item
will be written. However, if it doesn't, `append`

will silently overwrite
the next item. It is up to the application to ensure that the `TList`

points to a `TNil`

, or that overwriting an item in this case is desirable.

appendList :: TList a -> [a] -> STM (TList a)Source

*O(n)*. Append a list of items, returning the new write end.

fromList :: [a] -> STM (TList a, TList a)Source

*O(n)*. Convert a pure list to a `TList`

, returning the head (read end)
and tail (write end) of the list.

# Traversal

These functions traverse the list strictly. They examine the list as
it is now; they do not `retry`

when the end of the list is reached.

drop :: Int -> TList a -> STM (TList a)Source

*O(n)*. Skip the given number of items. Return the end of the list if a
`TNil`

is reached.