Useful-0.0.5: Some useful functions and shorthands.



List operations, part of the Useful module.



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

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

 $ explodeI "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" '!'

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" " "

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",""]

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]]

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"