| |||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||||
| Description | |||||||||||||||||||||||||||||||||||||||
This module provides various helpful utilities for dealing with lists. Written by John Goerzen, jgoerzen@complete.org | |||||||||||||||||||||||||||||||||||||||
| Synopsis | |||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||||
| Tests | |||||||||||||||||||||||||||||||||||||||
| startswith :: Eq a => [a] -> [a] -> Bool | |||||||||||||||||||||||||||||||||||||||
Returns true if the given list starts with the specified elements; false otherwise. (This is an alias for Data.List.isPrefixOf.) Example: startswith "He" "Hello" -> True | |||||||||||||||||||||||||||||||||||||||
| endswith :: Eq a => [a] -> [a] -> Bool | |||||||||||||||||||||||||||||||||||||||
Returns true if the given list ends with the specified elements; false otherwise. (This is an alias for Data.List.isSuffixOf.) Example: endswith "lo" "Hello" -> True | |||||||||||||||||||||||||||||||||||||||
| contains :: Eq a => [a] -> [a] -> Bool | |||||||||||||||||||||||||||||||||||||||
Returns true if the given parameter is a sublist of the given list; false otherwise. Example: contains "Haskell" "I really like Haskell." -> True contains "Haskell" "OCaml is great." -> False | |||||||||||||||||||||||||||||||||||||||
| Association List Utilities | |||||||||||||||||||||||||||||||||||||||
| These functions are designed to augment the association list functions in Data.List and provide an interface similar to Data.FiniteMap for association lists. | |||||||||||||||||||||||||||||||||||||||
| addToAL :: Eq key => [(key, elt)] -> key -> elt -> [(key, elt)] | |||||||||||||||||||||||||||||||||||||||
| Adds the specified (key, value) pair to the given list, removing any existing pair with the same key already present. | |||||||||||||||||||||||||||||||||||||||
| delFromAL :: Eq key => [(key, a)] -> key -> [(key, a)] | |||||||||||||||||||||||||||||||||||||||
| Removes all (key, value) pairs from the given list where the key matches the given one. | |||||||||||||||||||||||||||||||||||||||
| flipAL :: (Eq key, Eq val) => [(key, val)] -> [(val, [key])] | |||||||||||||||||||||||||||||||||||||||
| Flips an association list. Converts (key1, val), (key2, val) pairs to (val, [key1, key2]). | |||||||||||||||||||||||||||||||||||||||
| Association List Conversions | |||||||||||||||||||||||||||||||||||||||
| strFromAL :: (Show a, Show b) => [(a, b)] -> String | |||||||||||||||||||||||||||||||||||||||
Converts an association list to a string. The string will have one pair per line, with the key and value both represented as a Haskell string. This function is designed to work with [(String, String)] association lists, but may work with other types as well. | |||||||||||||||||||||||||||||||||||||||
| strToAL :: (Read a, Read b) => String -> [(a, b)] | |||||||||||||||||||||||||||||||||||||||
The inverse of strFromAL, this function reads a string and outputs the appropriate association list. Like strFromAL, this is designed to work with [(String, String)] association lists but may also work with other objects with simple representations. | |||||||||||||||||||||||||||||||||||||||
| Conversions | |||||||||||||||||||||||||||||||||||||||
| split :: Eq a => [a] -> [a] -> [[a]] | |||||||||||||||||||||||||||||||||||||||
Given a delimiter and a list (or string), split into components. Example: split "," "foo,bar,,baz," -> ["foo", "bar", "", "baz", ""] split "ba" ",foo,bar,,baz," -> [",foo,","r,,","z,"] | |||||||||||||||||||||||||||||||||||||||
| join :: [a] -> [[a]] -> [a] | |||||||||||||||||||||||||||||||||||||||
Given a delimiter and a list of items (or strings), join the items by using the delimiter. Example: join "|" ["foo", "bar", "baz"] -> "foo|bar|baz" | |||||||||||||||||||||||||||||||||||||||
| replace :: Eq a => [a] -> [a] -> [a] -> [a] | |||||||||||||||||||||||||||||||||||||||
Given a list and a replacement list, replaces each occurance of the search list with the replacement list in the operation list. | |||||||||||||||||||||||||||||||||||||||
| genericJoin :: Show a => String -> [a] -> String | |||||||||||||||||||||||||||||||||||||||
Like join, but works with a list of anything showable, converting it to a String. Examples: genericJoin ", " [1, 2, 3, 4] -> "1, 2, 3, 4" genericJoin "|" ["foo", "bar", "baz"] -> "\"foo\"|\"bar\"|\"baz\"" | |||||||||||||||||||||||||||||||||||||||
| takeWhileList :: ([a] -> Bool) -> [a] -> [a] | |||||||||||||||||||||||||||||||||||||||
| Similar to Data.List.takeWhile, takes elements while the func is true. The function is given the remainder of the list to examine. | |||||||||||||||||||||||||||||||||||||||
| dropWhileList :: ([a] -> Bool) -> [a] -> [a] | |||||||||||||||||||||||||||||||||||||||
| Similar to Data.List.dropWhile, drops elements while the func is true. The function is given the remainder of the list to examine. | |||||||||||||||||||||||||||||||||||||||
| spanList :: ([a] -> Bool) -> [a] -> ([a], [a]) | |||||||||||||||||||||||||||||||||||||||
Similar to Data.List.span, but performs the test on the entire remaining list instead of just one element. spanList p xs is the same as (takeWhileList p xs, dropWhileList p xs) | |||||||||||||||||||||||||||||||||||||||
| breakList :: ([a] -> Bool) -> [a] -> ([a], [a]) | |||||||||||||||||||||||||||||||||||||||
| Similar to Data.List.break, but performs the test on the entire remaining list instead of just one element. | |||||||||||||||||||||||||||||||||||||||
| Miscellaneous | |||||||||||||||||||||||||||||||||||||||
| countElem :: Eq a => a -> [a] -> Int | |||||||||||||||||||||||||||||||||||||||
| Returns a count of the number of times the given element occured in the given list. | |||||||||||||||||||||||||||||||||||||||
| elemRIndex :: Eq a => a -> [a] -> Maybe Int | |||||||||||||||||||||||||||||||||||||||
| Returns the rightmost index of the given element in the given list. | |||||||||||||||||||||||||||||||||||||||
| alwaysElemRIndex :: Eq a => a -> [a] -> Int | |||||||||||||||||||||||||||||||||||||||
| Like elemRIndex, but returns -1 if there is nothing found. | |||||||||||||||||||||||||||||||||||||||
| seqList :: [a] -> [a] | |||||||||||||||||||||||||||||||||||||||
| Forces the evaluation of the entire list. | |||||||||||||||||||||||||||||||||||||||
| Produced by Haddock version 0.6 |