From de9f1a16b1ff1515f7cad26ff14add59283263dc Mon Sep 17 00:00:00 2001 From: Ellis Kesterton Date: Wed, 3 Jan 2024 20:43:01 +0000 Subject: [PATCH 1/2] Implement "mapSplitter" --- src/Data/List/Split.hs | 1 + src/Data/List/Split/Internals.hs | 13 +++++++++++++ 2 files changed, 14 insertions(+) diff --git a/src/Data/List/Split.hs b/src/Data/List/Split.hs index 1a12f99..46951a0 100644 --- a/src/Data/List/Split.hs +++ b/src/Data/List/Split.hs @@ -61,6 +61,7 @@ module Data.List.Split ( dropInitBlank, dropFinalBlank, dropInnerBlanks, + mapSplitter, -- ** Derived combinators -- $derived diff --git a/src/Data/List/Split/Internals.hs b/src/Data/List/Split/Internals.hs index d982137..0b71670 100644 --- a/src/Data/List/Split/Internals.hs +++ b/src/Data/List/Split/Internals.hs @@ -379,6 +379,19 @@ dropFinalBlank s = s {finalBlankPolicy = DropBlank} dropInnerBlanks :: Splitter a -> Splitter a dropInnerBlanks s = s {condensePolicy = DropBlankFields} +-- | Split over a different type of element by performing a preprocessing step. +-- +-- >>> split (mapSplitter snd $ oneOf "-_") $ zip [0..] "a-bc_d" +-- [[(0,'a')],[(1,'-')],[(2,'b'),(3,'c')],[(4,'_')],[(5,'d')]] +-- +-- >>> split (mapSplitter toLower $ dropDelims $ whenElt (== 'x')) "abXcxd" +-- ["ab","c","d"] +mapSplitter :: (b -> a) -> Splitter a -> Splitter b +mapSplitter f (Splitter d dp cp ibp fbp) = Splitter (mapDelimiter f d) dp cp ibp fbp + where + mapDelimiter :: (b -> a) -> Delimiter a -> Delimiter b + mapDelimiter g (Delimiter xs) = Delimiter $ map (. g) xs + -- ** Derived combinators -- | Drop all blank chunks from the output, and condense consecutive From f7bc600f3477bb092fa67cff8ee5388b3cf1bb1e Mon Sep 17 00:00:00 2001 From: Ellis Kesterton <31514698+eayus@users.noreply.github.com> Date: Sun, 7 Jan 2024 17:10:54 +0000 Subject: [PATCH 2/2] Fix doctest imports --- src/Data/List/Split/Internals.hs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Data/List/Split/Internals.hs b/src/Data/List/Split/Internals.hs index 0b71670..03c3431 100644 --- a/src/Data/List/Split/Internals.hs +++ b/src/Data/List/Split/Internals.hs @@ -384,6 +384,7 @@ dropInnerBlanks s = s {condensePolicy = DropBlankFields} -- >>> split (mapSplitter snd $ oneOf "-_") $ zip [0..] "a-bc_d" -- [[(0,'a')],[(1,'-')],[(2,'b'),(3,'c')],[(4,'_')],[(5,'d')]] -- +-- >>> import Data.Char (toLower) -- >>> split (mapSplitter toLower $ dropDelims $ whenElt (== 'x')) "abXcxd" -- ["ab","c","d"] mapSplitter :: (b -> a) -> Splitter a -> Splitter b