module Util (module Util, toList, NonEmpty(..)) where import Data.Foldable (toList) 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))) uniq :: Eq a => [a] -> [a] uniq (x : y : xs) | x == y = uniq (y : xs) | otherwise = x : uniq (y : xs) uniq l = l