Useful-0.0.1: 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)

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

Alias of mod

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. Also remember, 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. THIS FUNCTION IS NOT COMPLETE.

 $ '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

Simple function that 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.