diff options
author | Tom Smeding <tom@tomsmeding.com> | 2021-12-01 19:22:21 +0100 |
---|---|---|
committer | Tom Smeding <tom@tomsmeding.com> | 2021-12-01 19:22:21 +0100 |
commit | 3dc0370ab576388b7fe6908ac73c4561551a494c (patch) | |
tree | 43276a34370552a7981946587c1f3df8b8f04020 /2021/Util.hs | |
parent | 833fcf24d661ef600d00c017ce7796b2fc938a17 (diff) |
2021
Diffstat (limited to '2021/Util.hs')
-rw-r--r-- | 2021/Util.hs | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/2021/Util.hs b/2021/Util.hs new file mode 100644 index 0000000..7cd674d --- /dev/null +++ b/2021/Util.hs @@ -0,0 +1,14 @@ +module Util where + +import Data.List +import Data.List.NonEmpty (NonEmpty(..), (<|)) + + +splitOn :: (a -> Bool) -> [a] -> NonEmpty [a] +splitOn _ [] = [] :| [] +splitOn f (x:xs) | f x = [] <| splitOn f xs + | otherwise = let l :| ls = splitOn f xs + in (x : l) :| ls + +splits' :: [a] -> [(a, [a])] +splits' l = zip l (zipWith (++) (inits l) (tail (tails l))) |