summaryrefslogtreecommitdiff
path: root/src/GF/Data/Operations.hs
diff options
context:
space:
mode:
authoraarne <unknown>2004-06-15 13:55:54 +0000
committeraarne <unknown>2004-06-15 13:55:54 +0000
commit3fb91e0f448aa4be317a112fdc95673fb99fa6f6 (patch)
treebfa5f16b457b06eca610541663776051d6deb66e /src/GF/Data/Operations.hs
parent652618742aa1dd10b1a53bb132a476a91f1dc3ba (diff)
improved make facility: remember state if fails; does not need source
Diffstat (limited to 'src/GF/Data/Operations.hs')
-rw-r--r--src/GF/Data/Operations.hs9
1 files changed, 9 insertions, 0 deletions
diff --git a/src/GF/Data/Operations.hs b/src/GF/Data/Operations.hs
index 9c374fe83..9bed80392 100644
--- a/src/GF/Data/Operations.hs
+++ b/src/GF/Data/Operations.hs
@@ -122,6 +122,15 @@ mapErrN maxN f xs = Ok (ys, unlines (errHdr : ss2))
nss = length ss
fxs = map f xs
+-- like foldM, but also return the latest value if fails
+
+foldErr :: (a -> b -> Err a) -> a -> [b] -> Err (a, Maybe String)
+foldErr f s xs = case xs of
+ [] -> return (s,Nothing)
+ x:xx -> case f s x of
+ Ok v -> foldErr f v xx
+ Bad m -> return $ (s, Just m)
+
-- !! with the error monad
(!?) :: [a] -> Int -> Err a
xs !? i = foldr (const . return) (Bad "too few elements in list") $ drop i xs