Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- chunk :: (Eq b) => [a] -> (a -> b) -> [(b, [a])]
- chunk [] _ = []
- chunk (x:xs) f = let fx = f x
- (h, t) = span ((==) fx . f) xs
- in [(fx,(x:h))] ++ chunk t f
- data ChunkType = Word | Blank deriving (Show, Eq)
- chunkByBlank :: Char -> ChunkType
- chunkByBlank ' ' = Blank
- chunkByBlank _ = Word
- main = putStrLn . show $ chunk "Haskell is awesome!!" chunkByBlank
- -- => [(Word,"Haskell"),(Blank," "),(Word,"is"),(Blank," "),(Word,"awesome!!")]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement