diff options
author | Tom Smeding <tom.smeding@gmail.com> | 2020-12-16 21:26:58 +0100 |
---|---|---|
committer | Tom Smeding <tom.smeding@gmail.com> | 2020-12-16 21:26:58 +0100 |
commit | 2d324ad69e72e56ff99ce53c55e248661a363b82 (patch) | |
tree | 64fc33f35393703a066a6dd37b08292722a45937 /2020/Util.hs | |
parent | ac45449f8882a76612dcca699f84f54f08edcff4 (diff) |
Day 13
Diffstat (limited to '2020/Util.hs')
-rw-r--r-- | 2020/Util.hs | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/2020/Util.hs b/2020/Util.hs new file mode 100644 index 0000000..7f5f941 --- /dev/null +++ b/2020/Util.hs @@ -0,0 +1,10 @@ +module Util where + +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 |