summaryrefslogtreecommitdiff
path: root/2020/Util.hs
blob: 7f5f941077ebede84d62b856d486df954f7b95e0 (plain)
1
2
3
4
5
6
7
8
9
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