From 3dc0370ab576388b7fe6908ac73c4561551a494c Mon Sep 17 00:00:00 2001 From: Tom Smeding Date: Wed, 1 Dec 2021 19:22:21 +0100 Subject: 2021 --- 2021/Util.hs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 2021/Util.hs (limited to '2021/Util.hs') 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))) -- cgit v1.2.3-54-g00ecf