From 2d324ad69e72e56ff99ce53c55e248661a363b82 Mon Sep 17 00:00:00 2001 From: Tom Smeding Date: Wed, 16 Dec 2020 21:26:58 +0100 Subject: Day 13 --- 2020/Util.hs | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 2020/Util.hs (limited to '2020/Util.hs') 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 -- cgit v1.2.3-54-g00ecf