aboutsummaryrefslogtreecommitdiffstats
path: root/src/Utils.hs
diff options
context:
space:
mode:
authorJan Tuomi <jans.tuomi@gmail.com>2022-12-11 13:51:04 +0200
committerJan Tuomi <jans.tuomi@gmail.com>2022-12-11 13:51:04 +0200
commit3f7d328d356c75c0ae57c67eb64fb5337361cce7 (patch)
treef57e11eb89b50aecce10016078d9bdddcadc796c /src/Utils.hs
parentca75962a335a9954962b0213e060e3895ddc69fb (diff)
Only evaluate fn arg when immediately calling function with that arg
Diffstat (limited to 'src/Utils.hs')
-rw-r--r--src/Utils.hs6
1 files changed, 6 insertions, 0 deletions
diff --git a/src/Utils.hs b/src/Utils.hs
index 01ecb17..1eabd72 100644
--- a/src/Utils.hs
+++ b/src/Utils.hs
@@ -376,3 +376,9 @@ foldStackMessage (LException st) = case st of
where
fmtPos p = if useless p then "" else (" at " ++ p)
useless p = "nonsense" `L.isPrefixOf` p || length p == 0
+
+fold1M :: (Monad m) => (a -> a -> m a) -> [a] -> m a
+fold1M _ (x:[]) = return x
+fold1M f (x:y:xs) = do ret <- f x y
+ fold1M f (ret : xs)
+fold1M _ [] = error $ "fold1M of empty list"