cga/MyPrelude.hs

25 lines
615 B
Haskell
Raw Normal View History

{-# OPTIONS_HADDOCK ignore-exports #-}
2014-10-10 15:40:08 +00:00
module MyPrelude where
-- |Used to create a common interface for default settings of data types.
class Def a where
def :: a
-- |Split an array into subarrays depending on a given condition.
splitBy :: (a -> Bool) -- ^ condition
-> [a] -- ^ array to split
-> [[a]] -- ^ splitted array
2014-10-09 22:19:05 +00:00
splitBy f s =
case dropWhile f s of
[] -> []
s' -> w : splitBy f s''
where (w, s'') = break f s'
2014-10-08 14:27:59 +00:00
-- |Remove a given item from a list.
removeItem :: (Eq a) => a -> [a] -> [a]
removeItem x = foldr (\x' y -> if x' == x then y else x':y) []