{-# LANGUAGE Rank2Types #-}
module Data.List.Split.Lens
(
splitting
, splittingOn
, splittingOneOf
, splittingWhen
, endingBy
, endingByOneOf
, wordingBy
, liningBy
, chunking
, splittingPlaces
, splittingPlacesBlanks
, delimiters
, delimiting
, condensing
, keepInitialBlanks
, keepFinalBlanks
) where
import Control.Lens
import Data.Monoid
import Data.List.Split
import Data.List.Split.Internals
splitting :: Splitter a -> Getting (Endo [a]) s a -> Fold s [a]
splitting s l f = coerce . traverse f . split s . toListOf l
{-# INLINE splitting #-}
splittingOn :: Eq a => [a] -> Getting (Endo [a]) s a -> Fold s [a]
splittingOn s l f = coerce . traverse f . splitOn s . toListOf l
{-# INLINE splittingOn #-}
splittingOneOf :: Eq a => [a] -> Getting (Endo [a]) s a -> Fold s [a]
splittingOneOf s l f = coerce . traverse f . splitOneOf s . toListOf l
{-# INLINE splittingOneOf #-}
splittingWhen :: (a -> Bool) -> Getting (Endo [a]) s a -> Fold s [a]
splittingWhen s l f = coerce . traverse f . splitWhen s . toListOf l
{-# INLINE splittingWhen #-}
endingBy :: Eq a => [a] -> Getting (Endo [a]) s a -> Fold s [a]
endingBy s l f = coerce . traverse f . endBy s . toListOf l
{-# INLINE endingBy #-}
endingByOneOf :: Eq a => [a] -> Getting (Endo [a]) s a -> Fold s [a]
endingByOneOf s l f = coerce . traverse f . endByOneOf s . toListOf l
{-# INLINE endingByOneOf #-}
wordingBy :: (a -> Bool) -> Getting (Endo [a]) s a -> Fold s [a]
wordingBy s l f = coerce . traverse f . wordsBy s . toListOf l
{-# INLINE wordingBy #-}
liningBy :: (a -> Bool) -> Getting (Endo [a]) s a -> Fold s [a]
liningBy s l f = coerce . traverse f . linesBy s . toListOf l
{-# INLINE liningBy #-}
chunking :: Int
-> Getting (Endo [a]) s a -> Fold s [a]
chunking s l f = coerce . traverse f . chunksOf s . toListOf l
{-# INLINE chunking #-}
splittingPlaces :: Integral n => [n] -> Getting (Endo [a]) s a -> Fold s [a]
splittingPlaces s l f = coerce . traverse f . splitPlaces s . toListOf l
{-# INLINE splittingPlaces #-}
splittingPlacesBlanks :: Integral n => [n] -> Getting (Endo [a]) s a -> Fold s [a]
splittingPlacesBlanks s l f = coerce . traverse f . splitPlacesBlanks s . toListOf l
{-# INLINE splittingPlacesBlanks #-}
delimiters :: Lens (Splitter a) (Splitter b) [a -> Bool] [b -> Bool]
delimiters f s@Splitter { delimiter = Delimiter ds } = f ds <&> \ds' -> s { delimiter = Delimiter ds' }
{-# INLINE delimiters #-}
delimiting :: Lens' (Splitter a) DelimPolicy
delimiting f s@Splitter { delimPolicy = p } = f p <&> \p' -> s { delimPolicy = p' }
{-# INLINE delimiting #-}
condensing :: Lens' (Splitter a) CondensePolicy
condensing f s@Splitter { condensePolicy = p } = f p <&> \p' -> s { condensePolicy = p' }
{-# INLINE condensing #-}
keepInitialBlanks :: Lens' (Splitter a) Bool
keepInitialBlanks f s@Splitter { initBlankPolicy = p } = f (keeps p) <&> \p' -> s { initBlankPolicy = end p' }
{-# INLINE keepInitialBlanks #-}
keepFinalBlanks :: Lens' (Splitter a) Bool
keepFinalBlanks f s@Splitter { finalBlankPolicy = p } = f (keeps p) <&> \p' -> s { finalBlankPolicy = end p' }
{-# INLINE keepFinalBlanks #-}
end :: Bool -> EndPolicy
end True = KeepBlank
end False = DropBlank
{-# INLINE end #-}
keeps :: EndPolicy -> Bool
keeps KeepBlank = True
keeps DropBlank = False
{-# INLINE keeps #-}