packages feed

safe 0.3.6 → 0.3.7

raw patch · 3 files changed

+24/−7 lines, 3 files

Files

CHANGES.txt view
@@ -1,5 +1,7 @@ Changelog for Safe +0.3.7+    Add Def variants of the Exact functions 0.3.6     #6, remove unnecessary Ord constraints from maximumBy/minimumBy 0.3.5
Safe/Exact.hs view
@@ -20,15 +20,16 @@     takeExact, dropExact, splitAtExact,     zipExact, zipWithExact,     -- * Safe wrappers-    takeExactMay, takeExactNote,-    dropExactMay, dropExactNote,-    splitAtExactMay, splitAtExactNote,-    zipExactMay, zipExactNote,-    zipWithExactMay, zipWithExactNote,+    takeExactMay, takeExactNote, takeExactDef,+    dropExactMay, dropExactNote, dropExactDef,+    splitAtExactMay, splitAtExactNote, splitAtExactDef,+    zipExactMay, zipExactNote, zipExactDef,+    zipWithExactMay, zipWithExactNote, zipWithExactDef,     ) where  import Control.Arrow-+import Data.Maybe+import Safe.Util  --------------------------------------------------------------------- -- HELPERS@@ -92,12 +93,18 @@ takeExactMay :: Int -> [a] -> Maybe [a] takeExactMay = splitAtExact_ (const Nothing) (const $ Just []) (\a -> fmap (a:)) +takeExactDef :: [a] -> Int -> [a] -> [a]+takeExactDef def = fromMaybe def .^ takeExactMay+ dropExactNote :: String -> Int -> [a] -> [a] dropExactNote note = splitAtExact_ (addNote note "dropExactNote") id (flip const)  dropExactMay :: Int -> [a] -> Maybe [a] dropExactMay = splitAtExact_ (const Nothing) Just (flip const) +dropExactDef :: [a] -> Int -> [a] -> [a]+dropExactDef def = fromMaybe def .^ dropExactMay+ splitAtExactNote :: String -> Int -> [a] -> ([a], [a]) splitAtExactNote note = splitAtExact_ (addNote note "splitAtExactNote")     (\x -> ([], x)) (\a b -> first (a:) b)@@ -106,6 +113,8 @@ splitAtExactMay = splitAtExact_ (const Nothing)     (\x -> Just ([], x)) (\a b -> fmap (first (a:)) b) +splitAtExactDef :: ([a], [a]) -> Int -> [a] -> ([a], [a])+splitAtExactDef def = fromMaybe def .^ splitAtExactMay  --------------------------------------------------------------------- -- ZIP@@ -131,8 +140,14 @@ zipExactMay :: [a] -> [b] -> Maybe [(a,b)] zipExactMay = zipWithExact_ (const Nothing) (Just [])  (\a b xs -> fmap ((a,b) :) xs) +zipExactDef :: [(a,b)] -> [a] -> [b] -> [(a,b)]+zipExactDef def = fromMaybe def .^ zipExactMay+ zipWithExactNote :: String -> (a -> b -> c) -> [a] -> [b] -> [c] zipWithExactNote note f = zipWithExact_ (addNote note "zipWithExactNote") []  (\a b xs -> f a b : xs)  zipWithExactMay :: (a -> b -> c) -> [a] -> [b] -> Maybe [c] zipWithExactMay f = zipWithExact_ (const Nothing) (Just [])  (\a b xs -> fmap (f a b :) xs)++zipWithExactDef :: [c] -> (a -> b -> c) -> [a] -> [b] -> [c]+zipWithExactDef def = fromMaybe def .^^ zipWithExactMay
safe.cabal view
@@ -1,7 +1,7 @@ cabal-version:  >= 1.6 build-type:     Simple name:           safe-version:        0.3.6+version:        0.3.7 license:        BSD3 license-file:   LICENSE category:       Unclassified