blob: f021a88208de077e690c66070bc66d23899b0b3b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
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)))
|