Useful-0.0.6: Some useful functions and shorthands.

Useful.List

Description

List operations, part of the Useful module.

Synopsis

Documentation

explodeI :: Eq a => [a] -> a -> [[a]]Source

Takes a list item and splits a list around it, removing the item.

 $ explodeI "Hello there people" ' '
 ["Hello","there","people"]

splitI :: Eq a => [a] -> a -> [[a]]Source

Alias of explodeI

implodeI :: Eq a => [a] -> a -> [a]Source

Take a list item and concatinates each element of it around another given item.

 $implodeI "askjdnaskd" '!'
 "a!s!k!j!d!n!a!s!k!d"

joinI :: Eq a => [a] -> a -> [a]Source

alias of implodeI

explode :: Eq a => [a] -> [a] -> [[a]]Source

Takes a two lists and explodes the first into a new list, around the second. Removing the second list where it occurs.

 $explode "hello there people" "ll"
 ["he","o there people"]
 $explode "hello there people" " "
 ["hello","there","people"]

split :: Eq a => [a] -> [a] -> [[a]]Source

alias of explode

implode :: Eq a => [[a]] -> [a] -> [a]Source

Takes a list of lists and an extra list and concatinates the list of lists with the second list inbetween. When used with the empty list mimics concat

 $ implode ["helloasdad","asd hello","hello"] "!!"
 "helloasdad!!asd hello!!hello"

join :: Eq a => [[a]] -> [a] -> [a]Source

Alias of implode

rmEmpty :: Eq a => [[a]] -> [[a]]Source

In a list of lists this removes any occurances of the empty list. Can also be used to remove occurances of the empty string.

 $rmEmpty ["hello","","there","","people",""]
 ["hello","there","people"]

map2 :: (a -> b) -> [[a]] -> [[b]]Source

maps a function in depth N to the given list. map3, map4, map5 are also defined.

 $ map2 (*2) [[1,2,3,4],[1,1,1,2]]
 [[2,4,6,8],[2,2,2,4]]

map3 :: (a -> b) -> [[[a]]] -> [[[b]]]Source

map4 :: (a -> b) -> [[[[a]]]] -> [[[[b]]]]Source

map5 :: (a -> b) -> [[[[[a]]]]] -> [[[[[b]]]]]Source

replace :: Eq a => [a] -> [a] -> [a] -> [a]Source

Replaces any occurrences of the second list, with the third list, in the first list.

 $ replace "why hello hello there" "hello" "bonjour"
 "why bonjour bonjour there"

each :: [a] -> [[a]]Source

Takes a list of items and returns a list with each element in it's own single list.

 $ each "hello"
 ["h","e","l","l","o"]