blob: 1553c4c28ef182726b4214af939d96bb09c08fb6 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
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
|