{-# OPTIONS_HADDOCK prune #-}
module Data.List.Split.Internals where
import Data.List (genericSplitAt)
data Splitter a = Splitter { forall a. Splitter a -> Delimiter a
delimiter :: Delimiter a
, forall a. Splitter a -> DelimPolicy
delimPolicy :: DelimPolicy
, forall a. Splitter a -> CondensePolicy
condensePolicy :: CondensePolicy
, forall a. Splitter a -> EndPolicy
initBlankPolicy :: EndPolicy
, forall a. Splitter a -> EndPolicy
finalBlankPolicy :: EndPolicy
}
defaultSplitter :: Splitter a
defaultSplitter :: forall a. Splitter a
defaultSplitter = Splitter { delimiter :: Delimiter a
delimiter = forall a. [a -> Bool] -> Delimiter a
Delimiter [forall a b. a -> b -> a
const Bool
False]
, delimPolicy :: DelimPolicy
delimPolicy = DelimPolicy
Keep
, condensePolicy :: CondensePolicy
condensePolicy = CondensePolicy
KeepBlankFields
, initBlankPolicy :: EndPolicy
initBlankPolicy = EndPolicy
KeepBlank
, finalBlankPolicy :: EndPolicy
finalBlankPolicy = EndPolicy
KeepBlank
}
newtype Delimiter a = Delimiter [a -> Bool]
matchDelim :: Delimiter a -> [a] -> Maybe ([a],[a])
matchDelim :: forall a. Delimiter a -> [a] -> Maybe ([a], [a])
matchDelim (Delimiter []) [a]
xs = forall a. a -> Maybe a
Just ([],[a]
xs)
matchDelim (Delimiter [a -> Bool]
_) [] = forall a. Maybe a
Nothing
matchDelim (Delimiter (a -> Bool
p:[a -> Bool]
ps)) (a
x:[a]
xs)
| a -> Bool
p a
x = forall a. Delimiter a -> [a] -> Maybe ([a], [a])
matchDelim (forall a. [a -> Bool] -> Delimiter a
Delimiter [a -> Bool]
ps) [a]
xs forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \([a]
h,[a]
t) -> forall a. a -> Maybe a
Just (a
xforall a. a -> [a] -> [a]
:[a]
h,[a]
t)
| Bool
otherwise = forall a. Maybe a
Nothing
data DelimPolicy = Drop
| Keep
| KeepLeft
| KeepRight
deriving (DelimPolicy -> DelimPolicy -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DelimPolicy -> DelimPolicy -> Bool
$c/= :: DelimPolicy -> DelimPolicy -> Bool
== :: DelimPolicy -> DelimPolicy -> Bool
$c== :: DelimPolicy -> DelimPolicy -> Bool
Eq, Int -> DelimPolicy -> ShowS
[DelimPolicy] -> ShowS
DelimPolicy -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DelimPolicy] -> ShowS
$cshowList :: [DelimPolicy] -> ShowS
show :: DelimPolicy -> String
$cshow :: DelimPolicy -> String
showsPrec :: Int -> DelimPolicy -> ShowS
$cshowsPrec :: Int -> DelimPolicy -> ShowS
Show)
data CondensePolicy = Condense
| DropBlankFields
| KeepBlankFields
deriving (CondensePolicy -> CondensePolicy -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CondensePolicy -> CondensePolicy -> Bool
$c/= :: CondensePolicy -> CondensePolicy -> Bool
== :: CondensePolicy -> CondensePolicy -> Bool
$c== :: CondensePolicy -> CondensePolicy -> Bool
Eq, Int -> CondensePolicy -> ShowS
[CondensePolicy] -> ShowS
CondensePolicy -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CondensePolicy] -> ShowS
$cshowList :: [CondensePolicy] -> ShowS
show :: CondensePolicy -> String
$cshow :: CondensePolicy -> String
showsPrec :: Int -> CondensePolicy -> ShowS
$cshowsPrec :: Int -> CondensePolicy -> ShowS
Show)
data EndPolicy = DropBlank | KeepBlank
deriving (EndPolicy -> EndPolicy -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: EndPolicy -> EndPolicy -> Bool
$c/= :: EndPolicy -> EndPolicy -> Bool
== :: EndPolicy -> EndPolicy -> Bool
$c== :: EndPolicy -> EndPolicy -> Bool
Eq, Int -> EndPolicy -> ShowS
[EndPolicy] -> ShowS
EndPolicy -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [EndPolicy] -> ShowS
$cshowList :: [EndPolicy] -> ShowS
show :: EndPolicy -> String
$cshow :: EndPolicy -> String
showsPrec :: Int -> EndPolicy -> ShowS
$cshowsPrec :: Int -> EndPolicy -> ShowS
Show)
data Chunk a = Delim [a] | Text [a]
deriving (Int -> Chunk a -> ShowS
forall a. Show a => Int -> Chunk a -> ShowS
forall a. Show a => [Chunk a] -> ShowS
forall a. Show a => Chunk a -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Chunk a] -> ShowS
$cshowList :: forall a. Show a => [Chunk a] -> ShowS
show :: Chunk a -> String
$cshow :: forall a. Show a => Chunk a -> String
showsPrec :: Int -> Chunk a -> ShowS
$cshowsPrec :: forall a. Show a => Int -> Chunk a -> ShowS
Show, Chunk a -> Chunk a -> Bool
forall a. Eq a => Chunk a -> Chunk a -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Chunk a -> Chunk a -> Bool
$c/= :: forall a. Eq a => Chunk a -> Chunk a -> Bool
== :: Chunk a -> Chunk a -> Bool
$c== :: forall a. Eq a => Chunk a -> Chunk a -> Bool
Eq)
type SplitList a = [Chunk a]
fromElem :: Chunk a -> [a]
fromElem :: forall a. Chunk a -> [a]
fromElem (Text [a]
as) = [a]
as
fromElem (Delim [a]
as) = [a]
as
isDelim :: Chunk a -> Bool
isDelim :: forall a. Chunk a -> Bool
isDelim (Delim [a]
_) = Bool
True
isDelim Chunk a
_ = Bool
False
isText :: Chunk a -> Bool
isText :: forall a. Chunk a -> Bool
isText (Text [a]
_) = Bool
True
isText Chunk a
_ = Bool
False
splitInternal :: Delimiter a -> [a] -> SplitList a
splitInternal :: forall a. Delimiter a -> [a] -> SplitList a
splitInternal Delimiter a
_ [] = []
splitInternal Delimiter a
d [a]
xxs
| forall (t :: * -> *) a. Foldable t => t a -> Bool
null [a]
xs = Maybe ([a], [a]) -> [Chunk a]
toSplitList Maybe ([a], [a])
match
| Bool
otherwise = forall a. [a] -> Chunk a
Text [a]
xs forall a. a -> [a] -> [a]
: Maybe ([a], [a]) -> [Chunk a]
toSplitList Maybe ([a], [a])
match
where
([a]
xs,Maybe ([a], [a])
match) = forall a. Delimiter a -> [a] -> ([a], Maybe ([a], [a]))
breakDelim Delimiter a
d [a]
xxs
toSplitList :: Maybe ([a], [a]) -> [Chunk a]
toSplitList Maybe ([a], [a])
Nothing = []
toSplitList (Just ([],a
r:[a]
rs)) = forall a. [a] -> Chunk a
Delim [] forall a. a -> [a] -> [a]
: forall a. [a] -> Chunk a
Text [a
r] forall a. a -> [a] -> [a]
: forall a. Delimiter a -> [a] -> SplitList a
splitInternal Delimiter a
d [a]
rs
toSplitList (Just ([a]
delim,[a]
rest)) = forall a. [a] -> Chunk a
Delim [a]
delim forall a. a -> [a] -> [a]
: forall a. Delimiter a -> [a] -> SplitList a
splitInternal Delimiter a
d [a]
rest
breakDelim :: Delimiter a -> [a] -> ([a],Maybe ([a],[a]))
breakDelim :: forall a. Delimiter a -> [a] -> ([a], Maybe ([a], [a]))
breakDelim (Delimiter []) [a]
xs = ([],forall a. a -> Maybe a
Just ([],[a]
xs))
breakDelim Delimiter a
_ [] = ([],forall a. Maybe a
Nothing)
breakDelim Delimiter a
d xxs :: [a]
xxs@(a
x:[a]
xs) =
case forall a. Delimiter a -> [a] -> Maybe ([a], [a])
matchDelim Delimiter a
d [a]
xxs of
Maybe ([a], [a])
Nothing -> let ([a]
ys,Maybe ([a], [a])
match) = forall a. Delimiter a -> [a] -> ([a], Maybe ([a], [a]))
breakDelim Delimiter a
d [a]
xs in (a
xforall a. a -> [a] -> [a]
:[a]
ys,Maybe ([a], [a])
match)
Just ([a], [a])
match -> ([], forall a. a -> Maybe a
Just ([a], [a])
match)
postProcess :: Splitter a -> SplitList a -> SplitList a
postProcess :: forall a. Splitter a -> SplitList a -> SplitList a
postProcess Splitter a
s = forall a. EndPolicy -> SplitList a -> SplitList a
dropFinal (forall a. Splitter a -> EndPolicy
finalBlankPolicy Splitter a
s)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. EndPolicy -> SplitList a -> SplitList a
dropInitial (forall a. Splitter a -> EndPolicy
initBlankPolicy Splitter a
s)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. DelimPolicy -> SplitList a -> SplitList a
doMerge (forall a. Splitter a -> DelimPolicy
delimPolicy Splitter a
s)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. DelimPolicy -> SplitList a -> SplitList a
doDrop (forall a. Splitter a -> DelimPolicy
delimPolicy Splitter a
s)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. CondensePolicy -> SplitList a -> SplitList a
insertBlanks (forall a. Splitter a -> CondensePolicy
condensePolicy Splitter a
s)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. CondensePolicy -> SplitList a -> SplitList a
doCondense (forall a. Splitter a -> CondensePolicy
condensePolicy Splitter a
s)
doDrop :: DelimPolicy -> SplitList a -> SplitList a
doDrop :: forall a. DelimPolicy -> SplitList a -> SplitList a
doDrop DelimPolicy
Drop SplitList a
l = [ Chunk a
c | c :: Chunk a
c@(Text [a]
_) <- SplitList a
l ]
doDrop DelimPolicy
_ SplitList a
l = SplitList a
l
doCondense :: CondensePolicy -> SplitList a -> SplitList a
doCondense :: forall a. CondensePolicy -> SplitList a -> SplitList a
doCondense CondensePolicy
Condense SplitList a
ls = forall {a}. [Chunk a] -> [Chunk a]
condense' SplitList a
ls
where condense' :: [Chunk a] -> [Chunk a]
condense' [] = []
condense' (c :: Chunk a
c@(Text [a]
_) : [Chunk a]
l) = Chunk a
c forall a. a -> [a] -> [a]
: [Chunk a] -> [Chunk a]
condense' [Chunk a]
l
condense' [Chunk a]
l = (forall a. [a] -> Chunk a
Delim forall a b. (a -> b) -> a -> b
$ forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap forall a. Chunk a -> [a]
fromElem [Chunk a]
ds) forall a. a -> [a] -> [a]
: [Chunk a] -> [Chunk a]
condense' [Chunk a]
rest
where ([Chunk a]
ds,[Chunk a]
rest) = forall a. (a -> Bool) -> [a] -> ([a], [a])
span forall a. Chunk a -> Bool
isDelim [Chunk a]
l
doCondense CondensePolicy
_ SplitList a
ls = SplitList a
ls
insertBlanks :: CondensePolicy -> SplitList a -> SplitList a
insertBlanks :: forall a. CondensePolicy -> SplitList a -> SplitList a
insertBlanks CondensePolicy
_ [] = [forall a. [a] -> Chunk a
Text []]
insertBlanks CondensePolicy
cp (d :: Chunk a
d@(Delim [a]
_) : [Chunk a]
l) = forall a. [a] -> Chunk a
Text [] forall a. a -> [a] -> [a]
: forall a. CondensePolicy -> SplitList a -> SplitList a
insertBlanks' CondensePolicy
cp (Chunk a
dforall a. a -> [a] -> [a]
:[Chunk a]
l)
insertBlanks CondensePolicy
cp [Chunk a]
l = forall a. CondensePolicy -> SplitList a -> SplitList a
insertBlanks' CondensePolicy
cp [Chunk a]
l
insertBlanks' :: CondensePolicy -> SplitList a -> SplitList a
insertBlanks' :: forall a. CondensePolicy -> SplitList a -> SplitList a
insertBlanks' CondensePolicy
_ [] = []
insertBlanks' cp :: CondensePolicy
cp@CondensePolicy
DropBlankFields (d1 :: Chunk a
d1@(Delim [a]
_) : d2 :: Chunk a
d2@(Delim [a]
_) : [Chunk a]
l)
= Chunk a
d1 forall a. a -> [a] -> [a]
: forall a. CondensePolicy -> SplitList a -> SplitList a
insertBlanks' CondensePolicy
cp (Chunk a
d2forall a. a -> [a] -> [a]
:[Chunk a]
l)
insertBlanks' CondensePolicy
cp (d1 :: Chunk a
d1@(Delim [a]
_) : d2 :: Chunk a
d2@(Delim [a]
_) : [Chunk a]
l)
= Chunk a
d1 forall a. a -> [a] -> [a]
: forall a. [a] -> Chunk a
Text [] forall a. a -> [a] -> [a]
: forall a. CondensePolicy -> SplitList a -> SplitList a
insertBlanks' CondensePolicy
cp (Chunk a
d2forall a. a -> [a] -> [a]
:[Chunk a]
l)
insertBlanks' CondensePolicy
_ [d :: Chunk a
d@(Delim [a]
_)] = [Chunk a
d, forall a. [a] -> Chunk a
Text []]
insertBlanks' CondensePolicy
cp (Chunk a
c : [Chunk a]
l) = Chunk a
c forall a. a -> [a] -> [a]
: forall a. CondensePolicy -> SplitList a -> SplitList a
insertBlanks' CondensePolicy
cp [Chunk a]
l
doMerge :: DelimPolicy -> SplitList a -> SplitList a
doMerge :: forall a. DelimPolicy -> SplitList a -> SplitList a
doMerge DelimPolicy
KeepLeft = forall {a}. [Chunk a] -> [Chunk a]
mergeLeft
doMerge DelimPolicy
KeepRight = forall {a}. [Chunk a] -> [Chunk a]
mergeRight
doMerge DelimPolicy
_ = forall a. a -> a
id
mergeLeft :: SplitList a -> SplitList a
mergeLeft :: forall {a}. [Chunk a] -> [Chunk a]
mergeLeft [] = []
mergeLeft ((Delim [a]
d) : (Text [a]
c) : [Chunk a]
l) = forall a. [a] -> Chunk a
Text ([a]
dforall a. [a] -> [a] -> [a]
++[a]
c) forall a. a -> [a] -> [a]
: forall {a}. [Chunk a] -> [Chunk a]
mergeLeft [Chunk a]
l
mergeLeft (Chunk a
c : [Chunk a]
l) = Chunk a
c forall a. a -> [a] -> [a]
: forall {a}. [Chunk a] -> [Chunk a]
mergeLeft [Chunk a]
l
mergeRight :: SplitList a -> SplitList a
mergeRight :: forall {a}. [Chunk a] -> [Chunk a]
mergeRight [] = []
mergeRight ((Text [a]
c) : [Chunk a]
l) = forall a. [a] -> Chunk a
Text ([a]
cforall a. [a] -> [a] -> [a]
++[a]
d) forall a. a -> [a] -> [a]
: forall {a}. [Chunk a] -> [Chunk a]
mergeRight [Chunk a]
lTail
where ([a]
d, [Chunk a]
lTail) = case [Chunk a]
l of
Delim [a]
d' : [Chunk a]
l' -> ([a]
d', [Chunk a]
l')
[Chunk a]
_ -> ([], [Chunk a]
l)
mergeRight (Chunk a
c : [Chunk a]
l) = Chunk a
c forall a. a -> [a] -> [a]
: forall {a}. [Chunk a] -> [Chunk a]
mergeRight [Chunk a]
l
dropInitial :: EndPolicy -> SplitList a -> SplitList a
dropInitial :: forall a. EndPolicy -> SplitList a -> SplitList a
dropInitial EndPolicy
DropBlank (Text [] : [Chunk a]
l) = [Chunk a]
l
dropInitial EndPolicy
_ [Chunk a]
l = [Chunk a]
l
dropFinal :: EndPolicy -> SplitList a -> SplitList a
dropFinal :: forall a. EndPolicy -> SplitList a -> SplitList a
dropFinal EndPolicy
_ [] = []
dropFinal EndPolicy
DropBlank [Chunk a]
l = forall {a}. [Chunk a] -> [Chunk a]
dropFinal' [Chunk a]
l
where dropFinal' :: [Chunk a] -> [Chunk a]
dropFinal' [] = []
dropFinal' [Text []] = []
dropFinal' (Chunk a
x:[Chunk a]
xs) = Chunk a
xforall a. a -> [a] -> [a]
:[Chunk a] -> [Chunk a]
dropFinal' [Chunk a]
xs
dropFinal EndPolicy
_ [Chunk a]
l = [Chunk a]
l
split :: Splitter a -> [a] -> [[a]]
split :: forall a. Splitter a -> [a] -> [[a]]
split Splitter a
s = forall a b. (a -> b) -> [a] -> [b]
map forall a. Chunk a -> [a]
fromElem forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Splitter a -> SplitList a -> SplitList a
postProcess Splitter a
s forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Delimiter a -> [a] -> SplitList a
splitInternal (forall a. Splitter a -> Delimiter a
delimiter Splitter a
s)
oneOf :: Eq a => [a] -> Splitter a
oneOf :: forall a. Eq a => [a] -> Splitter a
oneOf [a]
elts = forall a. Splitter a
defaultSplitter { delimiter :: Delimiter a
delimiter = forall a. [a -> Bool] -> Delimiter a
Delimiter [(forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [a]
elts)] }
onSublist :: Eq a => [a] -> Splitter a
onSublist :: forall a. Eq a => [a] -> Splitter a
onSublist [a]
lst = forall a. Splitter a
defaultSplitter { delimiter :: Delimiter a
delimiter = forall a. [a -> Bool] -> Delimiter a
Delimiter (forall a b. (a -> b) -> [a] -> [b]
map forall a. Eq a => a -> a -> Bool
(==) [a]
lst) }
whenElt :: (a -> Bool) -> Splitter a
whenElt :: forall a. (a -> Bool) -> Splitter a
whenElt a -> Bool
p = forall a. Splitter a
defaultSplitter { delimiter :: Delimiter a
delimiter = forall a. [a -> Bool] -> Delimiter a
Delimiter [a -> Bool
p] }
dropDelims :: Splitter a -> Splitter a
dropDelims :: forall a. Splitter a -> Splitter a
dropDelims Splitter a
s = Splitter a
s { delimPolicy :: DelimPolicy
delimPolicy = DelimPolicy
Drop }
keepDelimsL :: Splitter a -> Splitter a
keepDelimsL :: forall a. Splitter a -> Splitter a
keepDelimsL Splitter a
s = Splitter a
s { delimPolicy :: DelimPolicy
delimPolicy = DelimPolicy
KeepLeft }
keepDelimsR :: Splitter a -> Splitter a
keepDelimsR :: forall a. Splitter a -> Splitter a
keepDelimsR Splitter a
s = Splitter a
s { delimPolicy :: DelimPolicy
delimPolicy = DelimPolicy
KeepRight }
condense :: Splitter a -> Splitter a
condense :: forall a. Splitter a -> Splitter a
condense Splitter a
s = Splitter a
s { condensePolicy :: CondensePolicy
condensePolicy = CondensePolicy
Condense }
dropInitBlank :: Splitter a -> Splitter a
dropInitBlank :: forall a. Splitter a -> Splitter a
dropInitBlank Splitter a
s = Splitter a
s { initBlankPolicy :: EndPolicy
initBlankPolicy = EndPolicy
DropBlank }
dropFinalBlank :: Splitter a -> Splitter a
dropFinalBlank :: forall a. Splitter a -> Splitter a
dropFinalBlank Splitter a
s = Splitter a
s { finalBlankPolicy :: EndPolicy
finalBlankPolicy = EndPolicy
DropBlank }
dropInnerBlanks :: Splitter a -> Splitter a
dropInnerBlanks :: forall a. Splitter a -> Splitter a
dropInnerBlanks Splitter a
s = Splitter a
s { condensePolicy :: CondensePolicy
condensePolicy = CondensePolicy
DropBlankFields }
dropBlanks :: Splitter a -> Splitter a
dropBlanks :: forall a. Splitter a -> Splitter a
dropBlanks = forall a. Splitter a -> Splitter a
dropInitBlank forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Splitter a -> Splitter a
dropFinalBlank forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Splitter a -> Splitter a
condense
startsWith :: Eq a => [a] -> Splitter a
startsWith :: forall a. Eq a => [a] -> Splitter a
startsWith = forall a. Splitter a -> Splitter a
dropInitBlank forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Splitter a -> Splitter a
keepDelimsL forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Eq a => [a] -> Splitter a
onSublist
startsWithOneOf :: Eq a => [a] -> Splitter a
startsWithOneOf :: forall a. Eq a => [a] -> Splitter a
startsWithOneOf = forall a. Splitter a -> Splitter a
dropInitBlank forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Splitter a -> Splitter a
keepDelimsL forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Eq a => [a] -> Splitter a
oneOf
endsWith :: Eq a => [a] -> Splitter a
endsWith :: forall a. Eq a => [a] -> Splitter a
endsWith = forall a. Splitter a -> Splitter a
dropFinalBlank forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Splitter a -> Splitter a
keepDelimsR forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Eq a => [a] -> Splitter a
onSublist
endsWithOneOf :: Eq a => [a] -> Splitter a
endsWithOneOf :: forall a. Eq a => [a] -> Splitter a
endsWithOneOf = forall a. Splitter a -> Splitter a
dropFinalBlank forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Splitter a -> Splitter a
keepDelimsR forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Eq a => [a] -> Splitter a
oneOf
splitOneOf :: Eq a => [a] -> [a] -> [[a]]
splitOneOf :: forall a. Eq a => [a] -> [a] -> [[a]]
splitOneOf = forall a. Splitter a -> [a] -> [[a]]
split forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Splitter a -> Splitter a
dropDelims forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Eq a => [a] -> Splitter a
oneOf
splitOn :: Eq a => [a] -> [a] -> [[a]]
splitOn :: forall a. Eq a => [a] -> [a] -> [[a]]
splitOn = forall a. Splitter a -> [a] -> [[a]]
split forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Splitter a -> Splitter a
dropDelims forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Eq a => [a] -> Splitter a
onSublist
splitWhen :: (a -> Bool) -> [a] -> [[a]]
splitWhen :: forall a. (a -> Bool) -> [a] -> [[a]]
splitWhen = forall a. Splitter a -> [a] -> [[a]]
split forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Splitter a -> Splitter a
dropDelims forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. (a -> Bool) -> Splitter a
whenElt
{-# DEPRECATED sepBy "Use splitOn." #-}
sepBy :: Eq a => [a] -> [a] -> [[a]]
sepBy :: forall a. Eq a => [a] -> [a] -> [[a]]
sepBy = forall a. Eq a => [a] -> [a] -> [[a]]
splitOn
{-# DEPRECATED sepByOneOf "Use splitOneOf." #-}
sepByOneOf :: Eq a => [a] -> [a] -> [[a]]
sepByOneOf :: forall a. Eq a => [a] -> [a] -> [[a]]
sepByOneOf = forall a. Eq a => [a] -> [a] -> [[a]]
splitOneOf
endBy :: Eq a => [a] -> [a] -> [[a]]
endBy :: forall a. Eq a => [a] -> [a] -> [[a]]
endBy = forall a. Splitter a -> [a] -> [[a]]
split forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Splitter a -> Splitter a
dropFinalBlank forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Splitter a -> Splitter a
dropDelims forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Eq a => [a] -> Splitter a
onSublist
endByOneOf :: Eq a => [a] -> [a] -> [[a]]
endByOneOf :: forall a. Eq a => [a] -> [a] -> [[a]]
endByOneOf = forall a. Splitter a -> [a] -> [[a]]
split forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Splitter a -> Splitter a
dropFinalBlank forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Splitter a -> Splitter a
dropDelims forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Eq a => [a] -> Splitter a
oneOf
{-# DEPRECATED unintercalate "Use splitOn." #-}
unintercalate :: Eq a => [a] -> [a] -> [[a]]
unintercalate :: forall a. Eq a => [a] -> [a] -> [[a]]
unintercalate = forall a. Eq a => [a] -> [a] -> [[a]]
splitOn
wordsBy :: (a -> Bool) -> [a] -> [[a]]
wordsBy :: forall a. (a -> Bool) -> [a] -> [[a]]
wordsBy = forall a. Splitter a -> [a] -> [[a]]
split forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Splitter a -> Splitter a
dropBlanks forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Splitter a -> Splitter a
dropDelims forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. (a -> Bool) -> Splitter a
whenElt
linesBy :: (a -> Bool) -> [a] -> [[a]]
linesBy :: forall a. (a -> Bool) -> [a] -> [[a]]
linesBy = forall a. Splitter a -> [a] -> [[a]]
split forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Splitter a -> Splitter a
dropFinalBlank forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Splitter a -> Splitter a
dropDelims forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. (a -> Bool) -> Splitter a
whenElt
build :: ((a -> [a] -> [a]) -> [a] -> [a]) -> [a]
build :: forall a. ((a -> [a] -> [a]) -> [a] -> [a]) -> [a]
build (a -> [a] -> [a]) -> [a] -> [a]
g = (a -> [a] -> [a]) -> [a] -> [a]
g (:) []
chunksOf :: Int -> [e] -> [[e]]
chunksOf :: forall e. Int -> [e] -> [[e]]
chunksOf Int
i [e]
ls = forall a b. (a -> b) -> [a] -> [b]
map (forall a. Int -> [a] -> [a]
take Int
i) (forall a. ((a -> [a] -> [a]) -> [a] -> [a]) -> [a]
build (forall e a. [e] -> ([e] -> a -> a) -> a -> a
splitter [e]
ls)) where
splitter :: [e] -> ([e] -> a -> a) -> a -> a
splitter :: forall e a. [e] -> ([e] -> a -> a) -> a -> a
splitter [] [e] -> a -> a
_ a
n = a
n
splitter [e]
l [e] -> a -> a
c a
n = [e]
l [e] -> a -> a
`c` forall e a. [e] -> ([e] -> a -> a) -> a -> a
splitter (forall a. Int -> [a] -> [a]
drop Int
i [e]
l) [e] -> a -> a
c a
n
{-# DEPRECATED chunk "Use chunksOf." #-}
chunk :: Int -> [e] -> [[e]]
chunk :: forall e. Int -> [e] -> [[e]]
chunk = forall e. Int -> [e] -> [[e]]
chunksOf
{-# DEPRECATED splitEvery "Use chunksOf." #-}
splitEvery :: Int -> [e] -> [[e]]
splitEvery :: forall e. Int -> [e] -> [[e]]
splitEvery = forall e. Int -> [e] -> [[e]]
chunksOf
splitPlaces :: Integral a => [a] -> [e] -> [[e]]
splitPlaces :: forall a e. Integral a => [a] -> [e] -> [[e]]
splitPlaces [a]
is [e]
ys = forall a. ((a -> [a] -> [a]) -> [a] -> [a]) -> [a]
build (forall i b t. Integral i => [i] -> [b] -> ([b] -> t -> t) -> t -> t
splitPlacer [a]
is [e]
ys) where
splitPlacer :: Integral i => [i] -> [b] -> ([b] -> t -> t) -> t -> t
splitPlacer :: forall i b t. Integral i => [i] -> [b] -> ([b] -> t -> t) -> t -> t
splitPlacer [] [b]
_ [b] -> t -> t
_ t
n = t
n
splitPlacer [i]
_ [] [b] -> t -> t
_ t
n = t
n
splitPlacer (i
l:[i]
ls) [b]
xs [b] -> t -> t
c t
n = let ([b]
x1, [b]
x2) = forall i a. Integral i => i -> [a] -> ([a], [a])
genericSplitAt i
l [b]
xs
in [b]
x1 [b] -> t -> t
`c` forall i b t. Integral i => [i] -> [b] -> ([b] -> t -> t) -> t -> t
splitPlacer [i]
ls [b]
x2 [b] -> t -> t
c t
n
splitPlacesBlanks :: Integral a => [a] -> [e] -> [[e]]
splitPlacesBlanks :: forall a e. Integral a => [a] -> [e] -> [[e]]
splitPlacesBlanks [a]
is [e]
ys = forall a. ((a -> [a] -> [a]) -> [a] -> [a]) -> [a]
build (forall i b t. Integral i => [i] -> [b] -> ([b] -> t -> t) -> t -> t
splitPlacer [a]
is [e]
ys) where
splitPlacer :: Integral i => [i] -> [b] -> ([b] -> t -> t) -> t -> t
splitPlacer :: forall i b t. Integral i => [i] -> [b] -> ([b] -> t -> t) -> t -> t
splitPlacer [] [b]
_ [b] -> t -> t
_ t
n = t
n
splitPlacer (i
l:[i]
ls) [b]
xs [b] -> t -> t
c t
n = let ([b]
x1, [b]
x2) = forall i a. Integral i => i -> [a] -> ([a], [a])
genericSplitAt i
l [b]
xs
in [b]
x1 [b] -> t -> t
`c` forall i b t. Integral i => [i] -> [b] -> ([b] -> t -> t) -> t -> t
splitPlacer [i]
ls [b]
x2 [b] -> t -> t
c t
n
chop :: ([a] -> (b, [a])) -> [a] -> [b]
chop :: forall a b. ([a] -> (b, [a])) -> [a] -> [b]
chop [a] -> (b, [a])
_ [] = []
chop [a] -> (b, [a])
f [a]
as = b
b forall a. a -> [a] -> [a]
: forall a b. ([a] -> (b, [a])) -> [a] -> [b]
chop [a] -> (b, [a])
f [a]
as'
where (b
b, [a]
as') = [a] -> (b, [a])
f [a]
as
divvy :: Int -> Int -> [a] -> [[a]]
divvy :: forall a. Int -> Int -> [a] -> [[a]]
divvy Int
_ Int
_ [] = []
divvy Int
n Int
m [a]
lst = forall a. (a -> Bool) -> [a] -> [a]
filter (\[a]
ws -> (Int
n forall a. Eq a => a -> a -> Bool
== forall (t :: * -> *) a. Foldable t => t a -> Int
length [a]
ws)) [[a]]
choppedl
where choppedl :: [[a]]
choppedl = forall a b. ([a] -> (b, [a])) -> [a] -> [b]
chop (\[a]
xs -> (forall a. Int -> [a] -> [a]
take Int
n [a]
xs , forall a. Int -> [a] -> [a]
drop Int
m [a]
xs)) [a]
lst