-- Hoogle documentation, generated by Haddock
-- See Hoogle, http://www.haskell.org/hoogle/


-- | Library for safe (pattern match free) functions
--   
--   Partial functions from the base library, such as <tt>head</tt> and
--   <tt>!!</tt>, modified to return more descriptive error messages,
--   programmer defined error messages, <tt>Maybe</tt> wrapped results and
--   default values. These functions can be used to reduce the number of
--   unsafe pattern matches in your code.
@package safe
@version 0.3.3


-- | Equivalent versions to the <a>Safe</a> module, but generalised to work
--   over any <a>Foldable</a> type.
module Safe.Foldable

-- | <pre>
--   Same as Data.Foldable.foldl1
--   </pre>
foldl1Note :: Foldable t => String -> (a -> a -> a) -> t a -> a
foldl1Def :: Foldable t => a -> (a -> a -> a) -> t a -> a
foldl1May :: Foldable t => (a -> a -> a) -> t a -> Maybe a

-- | Default value is the mempty from a monoid
foldl1Safe :: (Monoid m, Foldable t) => (m -> m -> m) -> t m -> m

-- | <pre>
--   Same as Data.Foldable.foldr1
--   </pre>
foldr1Note :: Foldable t => String -> (a -> a -> a) -> t a -> a
foldr1Def :: Foldable t => a -> (a -> a -> a) -> t a -> a
foldr1May :: Foldable t => (a -> a -> a) -> t a -> Maybe a

-- | Default value is the mempty from a monoid
foldr1Safe :: (Monoid m, Foldable t) => (m -> m -> m) -> t m -> m

-- | <pre>
--   Same as Data.Foldable.find
--   </pre>
findJust :: Foldable t => (a -> Bool) -> t a -> a
findJustDef :: Foldable t => a -> (a -> Bool) -> t a -> a
findJustNote :: Foldable t => String -> (a -> Bool) -> t a -> a

-- | Default value is the mempty from a monoid
findJustSafe :: (Monoid m, Foldable t) => (m -> Bool) -> t m -> m


-- | A library for safe functions, based on standard functions that may
--   crash. For more details see
--   <a>http://community.haskell.org/~ndm/safe/</a>
--   
--   In general, each unsafe function has up to 4 forms. Since <a>tail</a>
--   has all the possible forms, it is fully documented. The others all
--   follow the same pattern.
--   
--   <ul>
--   <li><tt>Note</tt>, takes an extra argument which supplements the error
--   message, <a>tailNote</a></li>
--   <li><tt>Def</tt>, take an extra argument to give when a crash would
--   otherwise happen, <a>tailDef</a></li>
--   <li><tt>May</tt>, wraps the result in a Maybe, <a>tailMay</a></li>
--   <li><tt>Safe</tt>, returns a default type if possible,
--   <a>tailSafe</a></li>
--   </ul>
--   
--   This library also introduces three brand new functions:
--   
--   <ul>
--   <li><a>at</a> - synonym for <tt>(!!)</tt></li>
--   <li><a>lookupJust</a> - defined as <tt>lookupJust k = fromJust .
--   lookup k</tt></li>
--   <li><a>abort</a> - same as <tt>error</tt>, but different intended
--   meaning</li>
--   </ul>
module Safe

-- | <pre>
--   tailDef [12] [] = [12]
--   tailDef [12] [1,3,4] = [3,4]
--   </pre>
tailDef :: [a] -> [a] -> [a]

-- | <pre>
--   tailMay [] = Nothing
--   tailMay [1,3,4] = Just [3,4]
--   </pre>
tailMay :: [a] -> Maybe [a]

-- | <pre>
--   tail "help me" [] = error "Pattern match failure, tail [], help me"
--   tail "help me" [1,3,4] = [3,4]
--   </pre>
tailNote :: String -> [a] -> [a]

-- | <pre>
--   tailSafe [] = []
--   tailSafe [1,3,4] = [3,4]
--   </pre>
tailSafe :: [a] -> [a]
initDef :: [a] -> [a] -> [a]
initMay :: [a] -> Maybe [a]
initNote :: String -> [a] -> [a]
initSafe :: [a] -> [a]
headDef :: a -> [a] -> a
headMay :: [a] -> Maybe a
headNote :: String -> [a] -> a
lastDef :: a -> [a] -> a
lastMay :: [a] -> Maybe a
lastNote :: String -> [a] -> a
minimumDef :: Ord a => a -> [a] -> a
minimumMay :: Ord a => [a] -> Maybe a
minimumNote :: Ord a => String -> [a] -> a
maximumDef :: Ord a => a -> [a] -> a
maximumMay :: Ord a => [a] -> Maybe a
maximumNote :: Ord a => String -> [a] -> a
foldr1Def :: a -> (a -> a -> a) -> [a] -> a
foldr1May :: (a -> a -> a) -> [a] -> Maybe a
foldr1Note :: String -> (a -> a -> a) -> [a] -> a
foldl1Def :: a -> (a -> a -> a) -> [a] -> a
foldl1May :: (a -> a -> a) -> [a] -> Maybe a
foldl1Note :: String -> (a -> a -> a) -> [a] -> a
foldl1Def' :: a -> (a -> a -> a) -> [a] -> a
foldl1May' :: (a -> a -> a) -> [a] -> Maybe a
foldl1Note' :: String -> (a -> a -> a) -> [a] -> a

-- | See fromMaybe
fromJustDef :: a -> Maybe a -> a
fromJustNote :: String -> Maybe a -> a
assertNote :: String -> Bool -> a -> a

-- | Same as <tt>(!!)</tt>, but better error message
at :: [a] -> Int -> a
atDef :: a -> [a] -> Int -> a
atMay :: [a] -> Int -> Maybe a
atNote :: String -> [a] -> Int -> a
readDef :: Read a => a -> String -> a
readMay :: Read a => String -> Maybe a
readNote :: Read a => String -> String -> a

-- | <pre>
--   lookupJust key = fromJust . lookup key
--   </pre>
lookupJust :: Eq a => a -> [(a, b)] -> b
lookupJustDef :: Eq a => b -> a -> [(a, b)] -> b
lookupJustNote :: Eq a => String -> a -> [(a, b)] -> b

-- | <pre>
--   findJust op = fromJust . find op
--   </pre>
findJust :: (a -> Bool) -> [a] -> a
findJustDef :: a -> (a -> Bool) -> [a] -> a
findJustNote :: String -> (a -> Bool) -> [a] -> a

-- | Exactly the same as <tt>error</tt>. Use this for instances where the
--   program has decided to exit because of invalid user input, or the user
--   pressed quit etc. This allows <tt>error</tt> to be reserved for
--   genuine coding mistakes.
abort :: String -> a
