Useful-0.0.6: Some useful functions and shorthands.

Useful.General

Description

General shorthands and other small operations. Part of the Useful module.

Synopsis

Documentation

(!=) :: Eq a => a -> a -> BoolSource

Alias of as /= (not equal to)

(%) :: Integral a => a -> a -> aSource

Alias of mod

(?) :: Eq a => a -> [a] -> BoolSource

Works like python's "in" function. (Alias of elem). Simply checks if an item is in a list.

 $ "Hello" ? ["Hello","there","people"]
 True
 $ "Bonjour" ? ["Hello","there","people"]
 False

(??) :: Eq a => [a] -> [a] -> BoolSource

Alias of as isInFixOf. Checks if list is a sublist of another list

 $ "hello" ?? "Why hello there people"
 True
 $ [2,3] ?? [1,2,3,4]
 True
 $ "bonjour" ?? "why hello there people"
 False 

(?!) :: Eq a => a -> [a] -> IntSource

Returns the index of the first occurance of an item if it is in a list. Otherwise gives an error. Starts counting from 0!

NOTE: This is not like elemIndex! It does not return a Maybe Int it returns an error if the item is not in a list. Either use elemIndex or test using ? first.

 $ 'n' ?! "banana"
 2
 $ 'v' ?! "banana"
 *** Exception: Item not in list

(!/) :: [a] -> (Int, a) -> [a]Source

Takes a list and a pair (x,y) and inserts the item y into the list at position x

 $ ["hello","there","people"]  !/ (0,"bonjour")
 ["bonjour","there","people"]

(!) :: [a] -> Int -> Maybe aSource

Like !! but returns Maybe a

 $ [1,2,3,4] ! 5
 Nothing
 $ [1,2,3,4] ! 1
 Just 2

len :: [a] -> IntSource

alias of length

count :: [a] -> IntSource

alias of length

the :: [a] -> aSource

Takes the unit list and returns the unit

NOTE: Will return an error if not supplied with the unit list

 $ the ["hello"]
 "hello"
 $ the ["hello","there"]
 "*** Exception: function 'the' called with a list other than the unit list.