summaryrefslogtreecommitdiffstats
path: root/src/utils.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/utils.hs')
-rw-r--r--src/utils.hs10
1 files changed, 9 insertions, 1 deletions
diff --git a/src/utils.hs b/src/utils.hs
index 5b78682..4ffdf3b 100644
--- a/src/utils.hs
+++ b/src/utils.hs
@@ -1,5 +1,6 @@
module Utils where
+import Control.Monad.Except
import qualified Data.Bifunctor as B
(.>) = flip (.)
@@ -42,4 +43,11 @@ breakOn cond xs = break cond xs $> B.second (drop 1)
mix :: [a] -> [a] -> [a]
mix (x : xs) (y : ys) = x : y : mix xs ys
mix x [] = x
-mix [] y = y \ No newline at end of file
+mix [] y = y
+
+safeBreak cond ex = safeBreak' cond ex []
+
+safeBreak' _ ex _ [] = throwError ex
+safeBreak' cond ex acc lst@(x : xs)
+ | cond x = pure (acc, lst)
+ | otherwise = safeBreak' cond ex (x : acc) xs