Haskell Language Data.Text Splitting Text Values


Example

{-# LANGUAGE OverloadedStrings #-}

import qualified Data.Text as T

myText :: T.Text
myText = "mississippi"

splitOn breaks a Text up into a list of Texts on occurrences of a substring.

ghci> T.splitOn "ss" myText
["mi","i","ippi"]

splitOn is the inverse of intercalate.

ghci> intercalate "ss" (splitOn "ss" "mississippi")
"mississippi"

split breaks a Text value into chunks on characters that satisfy a Boolean predicate.

ghci> T.split (== 'i') myText
["m","ss","ss","pp",""]