<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <!--Rendered using the Haskell Html Library v0.2--> <HTML ><HEAD ><META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=UTF-8" ><TITLE >Data.Text</TITLE ><LINK HREF="haddock.css" REL="stylesheet" TYPE="text/css" ><SCRIPT SRC="haddock-util.js" TYPE="text/javascript" ></SCRIPT ><SCRIPT TYPE="text/javascript" >window.onload = function () {setSynopsis("mini_Data-Text.html")};</SCRIPT ></HEAD ><BODY ><TABLE CLASS="vanilla" CELLSPACING="0" CELLPADDING="0" ><TR ><TD CLASS="topbar" ><TABLE CLASS="vanilla" CELLSPACING="0" CELLPADDING="0" ><TR ><TD ><IMG SRC="haskell_icon.gif" WIDTH="16" HEIGHT="16" ALT=" " ></TD ><TD CLASS="title" >text-0.8.1.0: An efficient packed Unicode text type.</TD ><TD CLASS="topbut" ><A HREF="src/Data-Text.html" >Source code</A ></TD ><TD CLASS="topbut" ><A HREF="index.html" >Contents</A ></TD ><TD CLASS="topbut" ><A HREF="doc-index.html" >Index</A ></TD ></TR ></TABLE ></TD ></TR ><TR ><TD CLASS="modulebar" ><TABLE CLASS="vanilla" CELLSPACING="0" CELLPADDING="0" ><TR ><TD ><FONT SIZE="6" >Data.Text</FONT ></TD ><TD ALIGN="right" ><TABLE CLASS="narrow" CELLSPACING="0" CELLPADDING="0" ><TR ><TD CLASS="infohead" >Portability</TD ><TD CLASS="infoval" >GHC</TD ></TR ><TR ><TD CLASS="infohead" >Stability</TD ><TD CLASS="infoval" >experimental</TD ></TR ><TR ><TD CLASS="infohead" >Maintainer</TD ><TD CLASS="infoval" >bos@serpentine.com, rtomharper@googlemail.com, duncan@haskell.org</TD ></TR ></TABLE ></TD ></TR ></TABLE ></TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD ><TABLE CLASS="vanilla" CELLSPACING="0" CELLPADDING="0" ><TR ><TD CLASS="section4" ><B >Contents</B ></TD ></TR ><TR ><TD ><DL ><DT ><A HREF="#1" >Strict vs lazy types </A ></DT ><DT ><A HREF="#2" >Fusion </A ></DT ><DT ><A HREF="#3" >Types </A ></DT ><DT ><A HREF="#4" >Creation and elimination </A ></DT ><DT ><A HREF="#5" >Basic interface </A ></DT ><DT ><A HREF="#6" >Transformations </A ></DT ><DD ><DL ><DT ><A HREF="#7" >Case conversion </A ></DT ><DT ><A HREF="#8" >Justification </A ></DT ></DL ></DD ><DT ><A HREF="#9" >Folds </A ></DT ><DD ><DL ><DT ><A HREF="#10" >Special folds </A ></DT ></DL ></DD ><DT ><A HREF="#11" >Construction </A ></DT ><DD ><DL ><DT ><A HREF="#12" >Scans </A ></DT ><DT ><A HREF="#13" >Accumulating maps </A ></DT ><DT ><A HREF="#14" >Generation and unfolding </A ></DT ></DL ></DD ><DT ><A HREF="#15" >Substrings </A ></DT ><DD ><DL ><DT ><A HREF="#16" >Breaking strings </A ></DT ><DT ><A HREF="#17" >Breaking into many substrings </A ></DT ><DT ><A HREF="#18" >Breaking into lines and words </A ></DT ></DL ></DD ><DT ><A HREF="#19" >Predicates </A ></DT ><DD ><DL ><DT ><A HREF="#20" >View patterns </A ></DT ></DL ></DD ><DT ><A HREF="#21" >Searching </A ></DT ><DT ><A HREF="#22" >Indexing </A ></DT ><DT ><A HREF="#23" >Zipping and unzipping </A ></DT ></DL ></TD ></TR ></TABLE ></TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="section1" >Description</TD ></TR ><TR ><TD CLASS="doc" ><P >A time and space-efficient implementation of Unicode text using packed Word16 arrays. Suitable for performance critical use, both in terms of large data quantities and high speed. </P ><P >This module is intended to be imported <TT >qualified</TT >, to avoid name clashes with <A HREF="Prelude.html" >Prelude</A > functions, e.g. </P ><PRE > import qualified Data.Text as T </PRE ></TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="section1" >Synopsis</TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="body" ><TABLE CLASS="vanilla" CELLSPACING="0" CELLPADDING="0" ><TR ><TD CLASS="decl" ><SPAN CLASS="keyword" >data</SPAN > <A HREF="#t%3AText" >Text</A > </TD ></TR ><TR ><TD CLASS="s8" ></TD ></TR ><TR ><TD CLASS="decl" ><A HREF="#v%3Apack" >pack</A > :: <A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Char.html#t%3AString" >String</A > -> <A HREF="Data-Text.html#t%3AText" >Text</A ></TD ></TR ><TR ><TD CLASS="s8" ></TD ></TR ><TR ><TD CLASS="decl" ><A HREF="#v%3Aunpack" >unpack</A > :: <A HREF="Data-Text.html#t%3AText" >Text</A > -> <A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Char.html#t%3AString" >String</A ></TD ></TR ><TR ><TD CLASS="s8" ></TD ></TR ><TR ><TD CLASS="decl" ><A HREF="#v%3Asingleton" >singleton</A > :: <A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Char.html#t%3AChar" >Char</A > -> <A HREF="Data-Text.html#t%3AText" >Text</A ></TD ></TR ><TR ><TD CLASS="s8" ></TD ></TR ><TR ><TD CLASS="decl" ><A HREF="#v%3Aempty" >empty</A > :: <A HREF="Data-Text.html#t%3AText" >Text</A ></TD ></TR ><TR ><TD CLASS="s8" ></TD ></TR ><TR ><TD CLASS="decl" ><A HREF="#v%3Acons" >cons</A > :: <A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Char.html#t%3AChar" >Char</A > -> <A HREF="Data-Text.html#t%3AText" >Text</A > -> <A HREF="Data-Text.html#t%3AText" >Text</A ></TD ></TR ><TR ><TD CLASS="s8" ></TD ></TR ><TR ><TD CLASS="decl" ><A HREF="#v%3Asnoc" >snoc</A > :: <A HREF="Data-Text.html#t%3AText" >Text</A > -> <A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Char.html#t%3AChar" >Char</A > -> <A HREF="Data-Text.html#t%3AText" >Text</A ></TD ></TR ><TR ><TD CLASS="s8" ></TD ></TR ><TR ><TD CLASS="decl" ><A HREF="#v%3Aappend" >append</A > :: <A HREF="Data-Text.html#t%3AText" >Text</A > -> <A HREF="Data-Text.html#t%3AText" >Text</A > -> <A HREF="Data-Text.html#t%3AText" >Text</A ></TD ></TR ><TR ><TD CLASS="s8" ></TD ></TR ><TR ><TD CLASS="decl" ><A HREF="#v%3Auncons" >uncons</A > :: <A HREF="Data-Text.html#t%3AText" >Text</A > -> <A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Maybe.html#t%3AMaybe" >Maybe</A > (<A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Char.html#t%3AChar" >Char</A >, <A HREF="Data-Text.html#t%3AText" >Text</A >)</TD ></TR ><TR ><TD CLASS="s8" ></TD ></TR ><TR ><TD CLASS="decl" ><A HREF="#v%3Ahead" >head</A > :: <A HREF="Data-Text.html#t%3AText" >Text</A > -> <A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Char.html#t%3AChar" >Char</A ></TD ></TR ><TR ><TD CLASS="s8" ></TD ></TR ><TR ><TD CLASS="decl" ><A HREF="#v%3Alast" >last</A > :: <A HREF="Data-Text.html#t%3AText" >Text</A > -> <A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Char.html#t%3AChar" >Char</A ></TD ></TR ><TR ><TD CLASS="s8" ></TD ></TR ><TR ><TD CLASS="decl" ><A HREF="#v%3Atail" >tail</A > :: <A HREF="Data-Text.html#t%3AText" >Text</A > -> <A HREF="Data-Text.html#t%3AText" >Text</A ></TD ></TR ><TR ><TD CLASS="s8" ></TD ></TR ><TR ><TD CLASS="decl" ><A HREF="#v%3Ainit" >init</A > :: <A HREF="Data-Text.html#t%3AText" >Text</A > -> <A HREF="Data-Text.html#t%3AText" >Text</A ></TD ></TR ><TR ><TD CLASS="s8" ></TD ></TR ><TR ><TD CLASS="decl" ><A HREF="#v%3Anull" >null</A > :: <A HREF="Data-Text.html#t%3AText" >Text</A > -> <A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Bool.html#t%3ABool" >Bool</A ></TD ></TR ><TR ><TD CLASS="s8" ></TD ></TR ><TR ><TD CLASS="decl" ><A HREF="#v%3Alength" >length</A > :: <A HREF="Data-Text.html#t%3AText" >Text</A > -> <A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Int.html#t%3AInt" >Int</A ></TD ></TR ><TR ><TD CLASS="s8" ></TD ></TR ><TR ><TD CLASS="decl" ><A HREF="#v%3AcompareLength" >compareLength</A > :: <A HREF="Data-Text.html#t%3AText" >Text</A > -> <A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Int.html#t%3AInt" >Int</A > -> <A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Ord.html#t%3AOrdering" >Ordering</A ></TD ></TR ><TR ><TD CLASS="s8" ></TD ></TR ><TR ><TD CLASS="decl" ><A HREF="#v%3Amap" >map</A > :: (<A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Char.html#t%3AChar" >Char</A > -> <A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Char.html#t%3AChar" >Char</A >) -> <A HREF="Data-Text.html#t%3AText" >Text</A > -> <A HREF="Data-Text.html#t%3AText" >Text</A ></TD ></TR ><TR ><TD CLASS="s8" ></TD ></TR ><TR ><TD CLASS="decl" ><A HREF="#v%3Aintercalate" >intercalate</A > :: <A HREF="Data-Text.html#t%3AText" >Text</A > -> [<A HREF="Data-Text.html#t%3AText" >Text</A >] -> <A HREF="Data-Text.html#t%3AText" >Text</A ></TD ></TR ><TR ><TD CLASS="s8" ></TD ></TR ><TR ><TD CLASS="decl" ><A HREF="#v%3Aintersperse" >intersperse</A > :: <A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Char.html#t%3AChar" >Char</A > -> <A HREF="Data-Text.html#t%3AText" >Text</A > -> <A HREF="Data-Text.html#t%3AText" >Text</A ></TD ></TR ><TR ><TD CLASS="s8" ></TD ></TR ><TR ><TD CLASS="decl" ><A HREF="#v%3Atranspose" >transpose</A > :: [<A HREF="Data-Text.html#t%3AText" >Text</A >] -> [<A HREF="Data-Text.html#t%3AText" >Text</A >]</TD ></TR ><TR ><TD CLASS="s8" ></TD ></TR ><TR ><TD CLASS="decl" ><A HREF="#v%3Areverse" >reverse</A > :: <A HREF="Data-Text.html#t%3AText" >Text</A > -> <A HREF="Data-Text.html#t%3AText" >Text</A ></TD ></TR ><TR ><TD CLASS="s8" ></TD ></TR ><TR ><TD CLASS="decl" ><A HREF="#v%3Areplace" >replace</A > :: <A HREF="Data-Text.html#t%3AText" >Text</A > -> <A HREF="Data-Text.html#t%3AText" >Text</A > -> <A HREF="Data-Text.html#t%3AText" >Text</A > -> <A HREF="Data-Text.html#t%3AText" >Text</A ></TD ></TR ><TR ><TD CLASS="s8" ></TD ></TR ><TR ><TD CLASS="decl" ><A HREF="#v%3AtoCaseFold" >toCaseFold</A > :: <A HREF="Data-Text.html#t%3AText" >Text</A > -> <A HREF="Data-Text.html#t%3AText" >Text</A ></TD ></TR ><TR ><TD CLASS="s8" ></TD ></TR ><TR ><TD CLASS="decl" ><A HREF="#v%3AtoLower" >toLower</A > :: <A HREF="Data-Text.html#t%3AText" >Text</A > -> <A HREF="Data-Text.html#t%3AText" >Text</A ></TD ></TR ><TR ><TD CLASS="s8" ></TD ></TR ><TR ><TD CLASS="decl" ><A HREF="#v%3AtoUpper" >toUpper</A > :: <A HREF="Data-Text.html#t%3AText" >Text</A > -> <A HREF="Data-Text.html#t%3AText" >Text</A ></TD ></TR ><TR ><TD CLASS="s8" ></TD ></TR ><TR ><TD CLASS="decl" ><A HREF="#v%3AjustifyLeft" >justifyLeft</A > :: <A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Int.html#t%3AInt" >Int</A > -> <A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Char.html#t%3AChar" >Char</A > -> <A HREF="Data-Text.html#t%3AText" >Text</A > -> <A HREF="Data-Text.html#t%3AText" >Text</A ></TD ></TR ><TR ><TD CLASS="s8" ></TD ></TR ><TR ><TD CLASS="decl" ><A HREF="#v%3AjustifyRight" >justifyRight</A > :: <A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Int.html#t%3AInt" >Int</A > -> <A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Char.html#t%3AChar" >Char</A > -> <A HREF="Data-Text.html#t%3AText" >Text</A > -> <A HREF="Data-Text.html#t%3AText" >Text</A ></TD ></TR ><TR ><TD CLASS="s8" ></TD ></TR ><TR ><TD CLASS="decl" ><A HREF="#v%3Acenter" >center</A > :: <A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Int.html#t%3AInt" >Int</A > -> <A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Char.html#t%3AChar" >Char</A > -> <A HREF="Data-Text.html#t%3AText" >Text</A > -> <A HREF="Data-Text.html#t%3AText" >Text</A ></TD ></TR ><TR ><TD CLASS="s8" ></TD ></TR ><TR ><TD CLASS="decl" ><A HREF="#v%3Afoldl" >foldl</A > :: (a -> <A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Char.html#t%3AChar" >Char</A > -> a) -> a -> <A HREF="Data-Text.html#t%3AText" >Text</A > -> a</TD ></TR ><TR ><TD CLASS="s8" ></TD ></TR ><TR ><TD CLASS="decl" ><A HREF="#v%3Afoldl%27" >foldl'</A > :: (a -> <A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Char.html#t%3AChar" >Char</A > -> a) -> a -> <A HREF="Data-Text.html#t%3AText" >Text</A > -> a</TD ></TR ><TR ><TD CLASS="s8" ></TD ></TR ><TR ><TD CLASS="decl" ><A HREF="#v%3Afoldl1" >foldl1</A > :: (<A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Char.html#t%3AChar" >Char</A > -> <A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Char.html#t%3AChar" >Char</A > -> <A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Char.html#t%3AChar" >Char</A >) -> <A HREF="Data-Text.html#t%3AText" >Text</A > -> <A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Char.html#t%3AChar" >Char</A ></TD ></TR ><TR ><TD CLASS="s8" ></TD ></TR ><TR ><TD CLASS="decl" ><A HREF="#v%3Afoldl1%27" >foldl1'</A > :: (<A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Char.html#t%3AChar" >Char</A > -> <A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Char.html#t%3AChar" >Char</A > -> <A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Char.html#t%3AChar" >Char</A >) -> <A HREF="Data-Text.html#t%3AText" >Text</A > -> <A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Char.html#t%3AChar" >Char</A ></TD ></TR ><TR ><TD CLASS="s8" ></TD ></TR ><TR ><TD CLASS="decl" ><A HREF="#v%3Afoldr" >foldr</A > :: (<A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Char.html#t%3AChar" >Char</A > -> a -> a) -> a -> <A HREF="Data-Text.html#t%3AText" >Text</A > -> a</TD ></TR ><TR ><TD CLASS="s8" ></TD ></TR ><TR ><TD CLASS="decl" ><A HREF="#v%3Afoldr1" >foldr1</A > :: (<A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Char.html#t%3AChar" >Char</A > -> <A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Char.html#t%3AChar" >Char</A > -> <A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Char.html#t%3AChar" >Char</A >) -> <A HREF="Data-Text.html#t%3AText" >Text</A > -> <A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Char.html#t%3AChar" >Char</A ></TD ></TR ><TR ><TD CLASS="s8" ></TD ></TR ><TR ><TD CLASS="decl" ><A HREF="#v%3Aconcat" >concat</A > :: [<A HREF="Data-Text.html#t%3AText" >Text</A >] -> <A HREF="Data-Text.html#t%3AText" >Text</A ></TD ></TR ><TR ><TD CLASS="s8" ></TD ></TR ><TR ><TD CLASS="decl" ><A HREF="#v%3AconcatMap" >concatMap</A > :: (<A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Char.html#t%3AChar" >Char</A > -> <A HREF="Data-Text.html#t%3AText" >Text</A >) -> <A HREF="Data-Text.html#t%3AText" >Text</A > -> <A HREF="Data-Text.html#t%3AText" >Text</A ></TD ></TR ><TR ><TD CLASS="s8" ></TD ></TR ><TR ><TD CLASS="decl" ><A HREF="#v%3Aany" >any</A > :: (<A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Char.html#t%3AChar" >Char</A > -> <A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Bool.html#t%3ABool" >Bool</A >) -> <A HREF="Data-Text.html#t%3AText" >Text</A > -> <A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Bool.html#t%3ABool" >Bool</A ></TD ></TR ><TR ><TD CLASS="s8" ></TD ></TR ><TR ><TD CLASS="decl" ><A HREF="#v%3Aall" >all</A > :: (<A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Char.html#t%3AChar" >Char</A > -> <A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Bool.html#t%3ABool" >Bool</A >) -> <A HREF="Data-Text.html#t%3AText" >Text</A > -> <A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Bool.html#t%3ABool" >Bool</A ></TD ></TR ><TR ><TD CLASS="s8" ></TD ></TR ><TR ><TD CLASS="decl" ><A HREF="#v%3Amaximum" >maximum</A > :: <A HREF="Data-Text.html#t%3AText" >Text</A > -> <A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Char.html#t%3AChar" >Char</A ></TD ></TR ><TR ><TD CLASS="s8" ></TD ></TR ><TR ><TD CLASS="decl" ><A HREF="#v%3Aminimum" >minimum</A > :: <A HREF="Data-Text.html#t%3AText" >Text</A > -> <A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Char.html#t%3AChar" >Char</A ></TD ></TR ><TR ><TD CLASS="s8" ></TD ></TR ><TR ><TD CLASS="decl" ><A HREF="#v%3Ascanl" >scanl</A > :: (<A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Char.html#t%3AChar" >Char</A > -> <A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Char.html#t%3AChar" >Char</A > -> <A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Char.html#t%3AChar" >Char</A >) -> <A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Char.html#t%3AChar" >Char</A > -> <A HREF="Data-Text.html#t%3AText" >Text</A > -> <A HREF="Data-Text.html#t%3AText" >Text</A ></TD ></TR ><TR ><TD CLASS="s8" ></TD ></TR ><TR ><TD CLASS="decl" ><A HREF="#v%3Ascanl1" >scanl1</A > :: (<A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Char.html#t%3AChar" >Char</A > -> <A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Char.html#t%3AChar" >Char</A > -> <A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Char.html#t%3AChar" >Char</A >) -> <A HREF="Data-Text.html#t%3AText" >Text</A > -> <A HREF="Data-Text.html#t%3AText" >Text</A ></TD ></TR ><TR ><TD CLASS="s8" ></TD ></TR ><TR ><TD CLASS="decl" ><A HREF="#v%3Ascanr" >scanr</A > :: (<A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Char.html#t%3AChar" >Char</A > -> <A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Char.html#t%3AChar" >Char</A > -> <A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Char.html#t%3AChar" >Char</A >) -> <A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Char.html#t%3AChar" >Char</A > -> <A HREF="Data-Text.html#t%3AText" >Text</A > -> <A HREF="Data-Text.html#t%3AText" >Text</A ></TD ></TR ><TR ><TD CLASS="s8" ></TD ></TR ><TR ><TD CLASS="decl" ><A HREF="#v%3Ascanr1" >scanr1</A > :: (<A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Char.html#t%3AChar" >Char</A > -> <A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Char.html#t%3AChar" >Char</A > -> <A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Char.html#t%3AChar" >Char</A >) -> <A HREF="Data-Text.html#t%3AText" >Text</A > -> <A HREF="Data-Text.html#t%3AText" >Text</A ></TD ></TR ><TR ><TD CLASS="s8" ></TD ></TR ><TR ><TD CLASS="decl" ><A HREF="#v%3AmapAccumL" >mapAccumL</A > :: (a -> <A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Char.html#t%3AChar" >Char</A > -> (a, <A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Char.html#t%3AChar" >Char</A >)) -> a -> <A HREF="Data-Text.html#t%3AText" >Text</A > -> (a, <A HREF="Data-Text.html#t%3AText" >Text</A >)</TD ></TR ><TR ><TD CLASS="s8" ></TD ></TR ><TR ><TD CLASS="decl" ><A HREF="#v%3AmapAccumR" >mapAccumR</A > :: (a -> <A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Char.html#t%3AChar" >Char</A > -> (a, <A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Char.html#t%3AChar" >Char</A >)) -> a -> <A HREF="Data-Text.html#t%3AText" >Text</A > -> (a, <A HREF="Data-Text.html#t%3AText" >Text</A >)</TD ></TR ><TR ><TD CLASS="s8" ></TD ></TR ><TR ><TD CLASS="decl" ><A HREF="#v%3Areplicate" >replicate</A > :: <A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Int.html#t%3AInt" >Int</A > -> <A HREF="Data-Text.html#t%3AText" >Text</A > -> <A HREF="Data-Text.html#t%3AText" >Text</A ></TD ></TR ><TR ><TD CLASS="s8" ></TD ></TR ><TR ><TD CLASS="decl" ><A HREF="#v%3Aunfoldr" >unfoldr</A > :: (a -> <A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Maybe.html#t%3AMaybe" >Maybe</A > (<A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Char.html#t%3AChar" >Char</A >, a)) -> a -> <A HREF="Data-Text.html#t%3AText" >Text</A ></TD ></TR ><TR ><TD CLASS="s8" ></TD ></TR ><TR ><TD CLASS="decl" ><A HREF="#v%3AunfoldrN" >unfoldrN</A > :: <A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Int.html#t%3AInt" >Int</A > -> (a -> <A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Maybe.html#t%3AMaybe" >Maybe</A > (<A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Char.html#t%3AChar" >Char</A >, a)) -> a -> <A HREF="Data-Text.html#t%3AText" >Text</A ></TD ></TR ><TR ><TD CLASS="s8" ></TD ></TR ><TR ><TD CLASS="decl" ><A HREF="#v%3Atake" >take</A > :: <A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Int.html#t%3AInt" >Int</A > -> <A HREF="Data-Text.html#t%3AText" >Text</A > -> <A HREF="Data-Text.html#t%3AText" >Text</A ></TD ></TR ><TR ><TD CLASS="s8" ></TD ></TR ><TR ><TD CLASS="decl" ><A HREF="#v%3Adrop" >drop</A > :: <A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Int.html#t%3AInt" >Int</A > -> <A HREF="Data-Text.html#t%3AText" >Text</A > -> <A HREF="Data-Text.html#t%3AText" >Text</A ></TD ></TR ><TR ><TD CLASS="s8" ></TD ></TR ><TR ><TD CLASS="decl" ><A HREF="#v%3AtakeWhile" >takeWhile</A > :: (<A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Char.html#t%3AChar" >Char</A > -> <A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Bool.html#t%3ABool" >Bool</A >) -> <A HREF="Data-Text.html#t%3AText" >Text</A > -> <A HREF="Data-Text.html#t%3AText" >Text</A ></TD ></TR ><TR ><TD CLASS="s8" ></TD ></TR ><TR ><TD CLASS="decl" ><A HREF="#v%3AdropWhile" >dropWhile</A > :: (<A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Char.html#t%3AChar" >Char</A > -> <A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Bool.html#t%3ABool" >Bool</A >) -> <A HREF="Data-Text.html#t%3AText" >Text</A > -> <A HREF="Data-Text.html#t%3AText" >Text</A ></TD ></TR ><TR ><TD CLASS="s8" ></TD ></TR ><TR ><TD CLASS="decl" ><A HREF="#v%3AdropWhileEnd" >dropWhileEnd</A > :: (<A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Char.html#t%3AChar" >Char</A > -> <A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Bool.html#t%3ABool" >Bool</A >) -> <A HREF="Data-Text.html#t%3AText" >Text</A > -> <A HREF="Data-Text.html#t%3AText" >Text</A ></TD ></TR ><TR ><TD CLASS="s8" ></TD ></TR ><TR ><TD CLASS="decl" ><A HREF="#v%3AdropAround" >dropAround</A > :: (<A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Char.html#t%3AChar" >Char</A > -> <A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Bool.html#t%3ABool" >Bool</A >) -> <A HREF="Data-Text.html#t%3AText" >Text</A > -> <A HREF="Data-Text.html#t%3AText" >Text</A ></TD ></TR ><TR ><TD CLASS="s8" ></TD ></TR ><TR ><TD CLASS="decl" ><A HREF="#v%3Astrip" >strip</A > :: <A HREF="Data-Text.html#t%3AText" >Text</A > -> <A HREF="Data-Text.html#t%3AText" >Text</A ></TD ></TR ><TR ><TD CLASS="s8" ></TD ></TR ><TR ><TD CLASS="decl" ><A HREF="#v%3AstripStart" >stripStart</A > :: <A HREF="Data-Text.html#t%3AText" >Text</A > -> <A HREF="Data-Text.html#t%3AText" >Text</A ></TD ></TR ><TR ><TD CLASS="s8" ></TD ></TR ><TR ><TD CLASS="decl" ><A HREF="#v%3AstripEnd" >stripEnd</A > :: <A HREF="Data-Text.html#t%3AText" >Text</A > -> <A HREF="Data-Text.html#t%3AText" >Text</A ></TD ></TR ><TR ><TD CLASS="s8" ></TD ></TR ><TR ><TD CLASS="decl" ><A HREF="#v%3AsplitAt" >splitAt</A > :: <A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Int.html#t%3AInt" >Int</A > -> <A HREF="Data-Text.html#t%3AText" >Text</A > -> (<A HREF="Data-Text.html#t%3AText" >Text</A >, <A HREF="Data-Text.html#t%3AText" >Text</A >)</TD ></TR ><TR ><TD CLASS="s8" ></TD ></TR ><TR ><TD CLASS="decl" ><A HREF="#v%3AspanBy" >spanBy</A > :: (<A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Char.html#t%3AChar" >Char</A > -> <A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Bool.html#t%3ABool" >Bool</A >) -> <A HREF="Data-Text.html#t%3AText" >Text</A > -> (<A HREF="Data-Text.html#t%3AText" >Text</A >, <A HREF="Data-Text.html#t%3AText" >Text</A >)</TD ></TR ><TR ><TD CLASS="s8" ></TD ></TR ><TR ><TD CLASS="decl" ><A HREF="#v%3Abreak" >break</A > :: <A HREF="Data-Text.html#t%3AText" >Text</A > -> <A HREF="Data-Text.html#t%3AText" >Text</A > -> (<A HREF="Data-Text.html#t%3AText" >Text</A >, <A HREF="Data-Text.html#t%3AText" >Text</A >)</TD ></TR ><TR ><TD CLASS="s8" ></TD ></TR ><TR ><TD CLASS="decl" ><A HREF="#v%3AbreakEnd" >breakEnd</A > :: <A HREF="Data-Text.html#t%3AText" >Text</A > -> <A HREF="Data-Text.html#t%3AText" >Text</A > -> (<A HREF="Data-Text.html#t%3AText" >Text</A >, <A HREF="Data-Text.html#t%3AText" >Text</A >)</TD ></TR ><TR ><TD CLASS="s8" ></TD ></TR ><TR ><TD CLASS="decl" ><A HREF="#v%3AbreakBy" >breakBy</A > :: (<A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Char.html#t%3AChar" >Char</A > -> <A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Bool.html#t%3ABool" >Bool</A >) -> <A HREF="Data-Text.html#t%3AText" >Text</A > -> (<A HREF="Data-Text.html#t%3AText" >Text</A >, <A HREF="Data-Text.html#t%3AText" >Text</A >)</TD ></TR ><TR ><TD CLASS="s8" ></TD ></TR ><TR ><TD CLASS="decl" ><A HREF="#v%3Agroup" >group</A > :: <A HREF="Data-Text.html#t%3AText" >Text</A > -> [<A HREF="Data-Text.html#t%3AText" >Text</A >]</TD ></TR ><TR ><TD CLASS="s8" ></TD ></TR ><TR ><TD CLASS="decl" ><A HREF="#v%3AgroupBy" >groupBy</A > :: (<A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Char.html#t%3AChar" >Char</A > -> <A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Char.html#t%3AChar" >Char</A > -> <A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Bool.html#t%3ABool" >Bool</A >) -> <A HREF="Data-Text.html#t%3AText" >Text</A > -> [<A HREF="Data-Text.html#t%3AText" >Text</A >]</TD ></TR ><TR ><TD CLASS="s8" ></TD ></TR ><TR ><TD CLASS="decl" ><A HREF="#v%3Ainits" >inits</A > :: <A HREF="Data-Text.html#t%3AText" >Text</A > -> [<A HREF="Data-Text.html#t%3AText" >Text</A >]</TD ></TR ><TR ><TD CLASS="s8" ></TD ></TR ><TR ><TD CLASS="decl" ><A HREF="#v%3Atails" >tails</A > :: <A HREF="Data-Text.html#t%3AText" >Text</A > -> [<A HREF="Data-Text.html#t%3AText" >Text</A >]</TD ></TR ><TR ><TD CLASS="s8" ></TD ></TR ><TR ><TD CLASS="decl" ><A HREF="#v%3Asplit" >split</A > :: <A HREF="Data-Text.html#t%3AText" >Text</A > -> <A HREF="Data-Text.html#t%3AText" >Text</A > -> [<A HREF="Data-Text.html#t%3AText" >Text</A >]</TD ></TR ><TR ><TD CLASS="s8" ></TD ></TR ><TR ><TD CLASS="decl" ><A HREF="#v%3AsplitBy" >splitBy</A > :: (<A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Char.html#t%3AChar" >Char</A > -> <A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Bool.html#t%3ABool" >Bool</A >) -> <A HREF="Data-Text.html#t%3AText" >Text</A > -> [<A HREF="Data-Text.html#t%3AText" >Text</A >]</TD ></TR ><TR ><TD CLASS="s8" ></TD ></TR ><TR ><TD CLASS="decl" ><A HREF="#v%3AchunksOf" >chunksOf</A > :: <A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Int.html#t%3AInt" >Int</A > -> <A HREF="Data-Text.html#t%3AText" >Text</A > -> [<A HREF="Data-Text.html#t%3AText" >Text</A >]</TD ></TR ><TR ><TD CLASS="s8" ></TD ></TR ><TR ><TD CLASS="decl" ><A HREF="#v%3Alines" >lines</A > :: <A HREF="Data-Text.html#t%3AText" >Text</A > -> [<A HREF="Data-Text.html#t%3AText" >Text</A >]</TD ></TR ><TR ><TD CLASS="s8" ></TD ></TR ><TR ><TD CLASS="decl" ><A HREF="#v%3Awords" >words</A > :: <A HREF="Data-Text.html#t%3AText" >Text</A > -> [<A HREF="Data-Text.html#t%3AText" >Text</A >]</TD ></TR ><TR ><TD CLASS="s8" ></TD ></TR ><TR ><TD CLASS="decl" ><A HREF="#v%3Aunlines" >unlines</A > :: [<A HREF="Data-Text.html#t%3AText" >Text</A >] -> <A HREF="Data-Text.html#t%3AText" >Text</A ></TD ></TR ><TR ><TD CLASS="s8" ></TD ></TR ><TR ><TD CLASS="decl" ><A HREF="#v%3Aunwords" >unwords</A > :: [<A HREF="Data-Text.html#t%3AText" >Text</A >] -> <A HREF="Data-Text.html#t%3AText" >Text</A ></TD ></TR ><TR ><TD CLASS="s8" ></TD ></TR ><TR ><TD CLASS="decl" ><A HREF="#v%3AisPrefixOf" >isPrefixOf</A > :: <A HREF="Data-Text.html#t%3AText" >Text</A > -> <A HREF="Data-Text.html#t%3AText" >Text</A > -> <A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Bool.html#t%3ABool" >Bool</A ></TD ></TR ><TR ><TD CLASS="s8" ></TD ></TR ><TR ><TD CLASS="decl" ><A HREF="#v%3AisSuffixOf" >isSuffixOf</A > :: <A HREF="Data-Text.html#t%3AText" >Text</A > -> <A HREF="Data-Text.html#t%3AText" >Text</A > -> <A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Bool.html#t%3ABool" >Bool</A ></TD ></TR ><TR ><TD CLASS="s8" ></TD ></TR ><TR ><TD CLASS="decl" ><A HREF="#v%3AisInfixOf" >isInfixOf</A > :: <A HREF="Data-Text.html#t%3AText" >Text</A > -> <A HREF="Data-Text.html#t%3AText" >Text</A > -> <A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Bool.html#t%3ABool" >Bool</A ></TD ></TR ><TR ><TD CLASS="s8" ></TD ></TR ><TR ><TD CLASS="decl" ><A HREF="#v%3AstripPrefix" >stripPrefix</A > :: <A HREF="Data-Text.html#t%3AText" >Text</A > -> <A HREF="Data-Text.html#t%3AText" >Text</A > -> <A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Maybe.html#t%3AMaybe" >Maybe</A > <A HREF="Data-Text.html#t%3AText" >Text</A ></TD ></TR ><TR ><TD CLASS="s8" ></TD ></TR ><TR ><TD CLASS="decl" ><A HREF="#v%3AstripSuffix" >stripSuffix</A > :: <A HREF="Data-Text.html#t%3AText" >Text</A > -> <A HREF="Data-Text.html#t%3AText" >Text</A > -> <A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Maybe.html#t%3AMaybe" >Maybe</A > <A HREF="Data-Text.html#t%3AText" >Text</A ></TD ></TR ><TR ><TD CLASS="s8" ></TD ></TR ><TR ><TD CLASS="decl" ><A HREF="#v%3Afilter" >filter</A > :: (<A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Char.html#t%3AChar" >Char</A > -> <A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Bool.html#t%3ABool" >Bool</A >) -> <A HREF="Data-Text.html#t%3AText" >Text</A > -> <A HREF="Data-Text.html#t%3AText" >Text</A ></TD ></TR ><TR ><TD CLASS="s8" ></TD ></TR ><TR ><TD CLASS="decl" ><A HREF="#v%3Afind" >find</A > :: <A HREF="Data-Text.html#t%3AText" >Text</A > -> <A HREF="Data-Text.html#t%3AText" >Text</A > -> [(<A HREF="Data-Text.html#t%3AText" >Text</A >, <A HREF="Data-Text.html#t%3AText" >Text</A >)]</TD ></TR ><TR ><TD CLASS="s8" ></TD ></TR ><TR ><TD CLASS="decl" ><A HREF="#v%3AfindBy" >findBy</A > :: (<A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Char.html#t%3AChar" >Char</A > -> <A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Bool.html#t%3ABool" >Bool</A >) -> <A HREF="Data-Text.html#t%3AText" >Text</A > -> <A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Maybe.html#t%3AMaybe" >Maybe</A > <A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Char.html#t%3AChar" >Char</A ></TD ></TR ><TR ><TD CLASS="s8" ></TD ></TR ><TR ><TD CLASS="decl" ><A HREF="#v%3ApartitionBy" >partitionBy</A > :: (<A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Char.html#t%3AChar" >Char</A > -> <A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Bool.html#t%3ABool" >Bool</A >) -> <A HREF="Data-Text.html#t%3AText" >Text</A > -> (<A HREF="Data-Text.html#t%3AText" >Text</A >, <A HREF="Data-Text.html#t%3AText" >Text</A >)</TD ></TR ><TR ><TD CLASS="s8" ></TD ></TR ><TR ><TD CLASS="decl" ><A HREF="#v%3Aindex" >index</A > :: <A HREF="Data-Text.html#t%3AText" >Text</A > -> <A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Int.html#t%3AInt" >Int</A > -> <A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Char.html#t%3AChar" >Char</A ></TD ></TR ><TR ><TD CLASS="s8" ></TD ></TR ><TR ><TD CLASS="decl" ><A HREF="#v%3AfindIndex" >findIndex</A > :: (<A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Char.html#t%3AChar" >Char</A > -> <A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Bool.html#t%3ABool" >Bool</A >) -> <A HREF="Data-Text.html#t%3AText" >Text</A > -> <A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Maybe.html#t%3AMaybe" >Maybe</A > <A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Int.html#t%3AInt" >Int</A ></TD ></TR ><TR ><TD CLASS="s8" ></TD ></TR ><TR ><TD CLASS="decl" ><A HREF="#v%3Acount" >count</A > :: <A HREF="Data-Text.html#t%3AText" >Text</A > -> <A HREF="Data-Text.html#t%3AText" >Text</A > -> <A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Int.html#t%3AInt" >Int</A ></TD ></TR ><TR ><TD CLASS="s8" ></TD ></TR ><TR ><TD CLASS="decl" ><A HREF="#v%3Azip" >zip</A > :: <A HREF="Data-Text.html#t%3AText" >Text</A > -> <A HREF="Data-Text.html#t%3AText" >Text</A > -> [(<A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Char.html#t%3AChar" >Char</A >, <A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Char.html#t%3AChar" >Char</A >)]</TD ></TR ><TR ><TD CLASS="s8" ></TD ></TR ><TR ><TD CLASS="decl" ><A HREF="#v%3AzipWith" >zipWith</A > :: (<A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Char.html#t%3AChar" >Char</A > -> <A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Char.html#t%3AChar" >Char</A > -> <A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Char.html#t%3AChar" >Char</A >) -> <A HREF="Data-Text.html#t%3AText" >Text</A > -> <A HREF="Data-Text.html#t%3AText" >Text</A > -> <A HREF="Data-Text.html#t%3AText" >Text</A ></TD ></TR ></TABLE ></TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="section1" ><A NAME="1" ><A NAME="1" >Strict vs lazy types </A ></A ></TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="doc" ><P >This package provides both strict and lazy <TT ><A HREF="Data-Text.html#t%3AText" >Text</A ></TT > types. The strict type is provided by the Data.Text package, while the lazy type is provided by the Data.Text.Lazy package. Internally, the lazy <TT >Text</TT > type consists of a list of strict chunks. </P ><P >The strict <TT ><A HREF="Data-Text.html#t%3AText" >Text</A ></TT > type requires that an entire string fit into memory at once. The lazy <TT >Text</TT > type is capable of streaming strings that are larger than memory using a small memory footprint. In many cases, the overhead of chunked streaming makes the lazy <TT >Text</TT > type slower than its strict counterpart, but this is not always the case. Sometimes, the time complexity of a function in one module may be different from the other, due to their differing internal structures. </P ><P >Each module provides an almost identical API, with the main difference being that the strict module uses <TT ><A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Int.html#t%3AInt" >Int</A ></TT > values for lengths and counts, while the lazy module uses Int64 lengths. </P ></TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="section1" ><A NAME="2" ><A NAME="2" >Fusion </A ></A ></TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="doc" ><P >Most of the functions in this module are subject to <EM >fusion</EM >, meaning that a pipeline of such functions will usually allocate at most one <TT ><A HREF="Data-Text.html#t%3AText" >Text</A ></TT > value. </P ><P >As an example, consider the following pipeline: </P ><PRE > import Data.Text as T import Data.Text.Encoding as E countChars :: ByteString -> Int countChars = T.length . T.toUpper . E.decodeUtf8 </PRE ><P >From the type signatures involved, this looks like it should allocate one ByteString value, and two <TT ><A HREF="Data-Text.html#t%3AText" >Text</A ></TT > values. However, when a module is compiled with optimisation enabled under GHC, the two intermediate <TT ><A HREF="Data-Text.html#t%3AText" >Text</A ></TT > values will be optimised away, and the function will be compiled down to a single loop over the source ByteString. </P ><P >Functions that can be fused by the compiler are marked with the phrase "Subject to fusion". </P ></TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="section1" ><A NAME="3" ><A NAME="3" >Types </A ></A ></TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="topdecl" ><TABLE CLASS="declbar" ><TR ><TD CLASS="declname" ><SPAN CLASS="keyword" >data</SPAN > <A NAME="t:Text" ><A NAME="t%3AText" ></A ></A ><B >Text</B > </TD ><TD CLASS="declbut" ><A HREF="src/Data-Text-Internal.html#Text" >Source</A ></TD ></TR ></TABLE ></TD ></TR ><TR ><TD CLASS="body" ><TABLE CLASS="vanilla" CELLSPACING="0" CELLPADDING="0" ><TR ><TD CLASS="ndoc" >A space efficient, packed, unboxed Unicode text type. </TD ></TR ><TR ><TD CLASS="section4" ><IMG SRC="minus.gif" CLASS="coll" ONCLICK="toggle(this,'i:Text')" ALT="show/hide" > Instances</TD ></TR ><TR ><TD CLASS="body" ><DIV ID="i:Text" STYLE="display:block;" ><TABLE CLASS="vanilla" CELLSPACING="1" CELLPADDING="0" ><TR ><TD CLASS="decl" ><A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Eq.html#t%3AEq" >Eq</A > <A HREF="Data-Text.html#t%3AText" >Text</A ></TD ></TR ><TR ><TD CLASS="decl" ><A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Data.html#t%3AData" >Data</A > <A HREF="Data-Text.html#t%3AText" >Text</A ></TD ></TR ><TR ><TD CLASS="decl" ><A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Ord.html#t%3AOrd" >Ord</A > <A HREF="Data-Text.html#t%3AText" >Text</A ></TD ></TR ><TR ><TD CLASS="decl" ><A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Text-Read.html#t%3ARead" >Read</A > <A HREF="Data-Text.html#t%3AText" >Text</A ></TD ></TR ><TR ><TD CLASS="decl" ><A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Text-Show.html#t%3AShow" >Show</A > <A HREF="Data-Text.html#t%3AText" >Text</A ></TD ></TR ><TR ><TD CLASS="decl" ><A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Typeable.html#t%3ATypeable" >Typeable</A > <A HREF="Data-Text.html#t%3AText" >Text</A ></TD ></TR ><TR ><TD CLASS="decl" ><A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-String.html#t%3AIsString" >IsString</A > <A HREF="Data-Text.html#t%3AText" >Text</A ></TD ></TR ><TR ><TD CLASS="decl" ><A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Monoid.html#t%3AMonoid" >Monoid</A > <A HREF="Data-Text.html#t%3AText" >Text</A ></TD ></TR ><TR ><TD CLASS="decl" ><A HREF="/usr/share/doc/ghc/html/libraries/deepseq-1.1.0.0/Control-DeepSeq.html#t%3ANFData" >NFData</A > <A HREF="Data-Text.html#t%3AText" >Text</A ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE ></TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="section1" ><A NAME="4" ><A NAME="4" >Creation and elimination </A ></A ></TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="topdecl" ><TABLE CLASS="declbar" ><TR ><TD CLASS="declname" ><A NAME="v:pack" ><A NAME="v%3Apack" ></A ></A ><B >pack</B > :: <A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Char.html#t%3AString" >String</A > -> <A HREF="Data-Text.html#t%3AText" >Text</A ></TD ><TD CLASS="declbut" ><A HREF="src/Data-Text.html#pack" >Source</A ></TD ></TR ></TABLE ></TD ></TR ><TR ><TD CLASS="doc" ><EM >O(n)</EM > Convert a <TT ><A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Char.html#t%3AString" >String</A ></TT > into a <TT ><A HREF="Data-Text.html#t%3AText" >Text</A ></TT >. Subject to fusion. </TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="topdecl" ><TABLE CLASS="declbar" ><TR ><TD CLASS="declname" ><A NAME="v:unpack" ><A NAME="v%3Aunpack" ></A ></A ><B >unpack</B > :: <A HREF="Data-Text.html#t%3AText" >Text</A > -> <A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Char.html#t%3AString" >String</A ></TD ><TD CLASS="declbut" ><A HREF="src/Data-Text.html#unpack" >Source</A ></TD ></TR ></TABLE ></TD ></TR ><TR ><TD CLASS="doc" ><EM >O(n)</EM > Convert a Text into a String. Subject to fusion. </TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="topdecl" ><TABLE CLASS="declbar" ><TR ><TD CLASS="declname" ><A NAME="v:singleton" ><A NAME="v%3Asingleton" ></A ></A ><B >singleton</B > :: <A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Char.html#t%3AChar" >Char</A > -> <A HREF="Data-Text.html#t%3AText" >Text</A ></TD ><TD CLASS="declbut" ><A HREF="src/Data-Text.html#singleton" >Source</A ></TD ></TR ></TABLE ></TD ></TR ><TR ><TD CLASS="doc" ><EM >O(1)</EM > Convert a character into a Text. Subject to fusion. </TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="topdecl" ><TABLE CLASS="declbar" ><TR ><TD CLASS="declname" ><A NAME="v:empty" ><A NAME="v%3Aempty" ></A ></A ><B >empty</B > :: <A HREF="Data-Text.html#t%3AText" >Text</A ></TD ><TD CLASS="declbut" ><A HREF="src/Data-Text-Internal.html#empty" >Source</A ></TD ></TR ></TABLE ></TD ></TR ><TR ><TD CLASS="doc" ><EM >O(1)</EM > The empty <TT ><A HREF="Data-Text.html#t%3AText" >Text</A ></TT >. </TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="section1" ><A NAME="5" ><A NAME="5" >Basic interface </A ></A ></TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="topdecl" ><TABLE CLASS="declbar" ><TR ><TD CLASS="declname" ><A NAME="v:cons" ><A NAME="v%3Acons" ></A ></A ><B >cons</B > :: <A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Char.html#t%3AChar" >Char</A > -> <A HREF="Data-Text.html#t%3AText" >Text</A > -> <A HREF="Data-Text.html#t%3AText" >Text</A ></TD ><TD CLASS="declbut" ><A HREF="src/Data-Text.html#cons" >Source</A ></TD ></TR ></TABLE ></TD ></TR ><TR ><TD CLASS="doc" ><EM >O(n)</EM > Adds a character to the front of a <TT ><A HREF="Data-Text.html#t%3AText" >Text</A ></TT >. This function is more costly than its List counterpart because it requires copying a new array. Subject to fusion. </TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="topdecl" ><TABLE CLASS="declbar" ><TR ><TD CLASS="declname" ><A NAME="v:snoc" ><A NAME="v%3Asnoc" ></A ></A ><B >snoc</B > :: <A HREF="Data-Text.html#t%3AText" >Text</A > -> <A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Char.html#t%3AChar" >Char</A > -> <A HREF="Data-Text.html#t%3AText" >Text</A ></TD ><TD CLASS="declbut" ><A HREF="src/Data-Text.html#snoc" >Source</A ></TD ></TR ></TABLE ></TD ></TR ><TR ><TD CLASS="doc" ><EM >O(n)</EM > Adds a character to the end of a <TT ><A HREF="Data-Text.html#t%3AText" >Text</A ></TT >. This copies the entire array in the process, unless fused. Subject to fusion. </TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="topdecl" ><TABLE CLASS="declbar" ><TR ><TD CLASS="declname" ><A NAME="v:append" ><A NAME="v%3Aappend" ></A ></A ><B >append</B > :: <A HREF="Data-Text.html#t%3AText" >Text</A > -> <A HREF="Data-Text.html#t%3AText" >Text</A > -> <A HREF="Data-Text.html#t%3AText" >Text</A ></TD ><TD CLASS="declbut" ><A HREF="src/Data-Text.html#append" >Source</A ></TD ></TR ></TABLE ></TD ></TR ><TR ><TD CLASS="doc" ><EM >O(n)</EM > Appends one <TT ><A HREF="Data-Text.html#t%3AText" >Text</A ></TT > to the other by copying both of them into a new <TT ><A HREF="Data-Text.html#t%3AText" >Text</A ></TT >. Subject to fusion. </TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="topdecl" ><TABLE CLASS="declbar" ><TR ><TD CLASS="declname" ><A NAME="v:uncons" ><A NAME="v%3Auncons" ></A ></A ><B >uncons</B > :: <A HREF="Data-Text.html#t%3AText" >Text</A > -> <A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Maybe.html#t%3AMaybe" >Maybe</A > (<A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Char.html#t%3AChar" >Char</A >, <A HREF="Data-Text.html#t%3AText" >Text</A >)</TD ><TD CLASS="declbut" ><A HREF="src/Data-Text.html#uncons" >Source</A ></TD ></TR ></TABLE ></TD ></TR ><TR ><TD CLASS="doc" ><EM >O(1)</EM > Returns the first character and rest of a <TT ><A HREF="Data-Text.html#t%3AText" >Text</A ></TT >, or <TT ><A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Maybe.html#v%3ANothing" >Nothing</A ></TT > if empty. Subject to fusion. </TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="topdecl" ><TABLE CLASS="declbar" ><TR ><TD CLASS="declname" ><A NAME="v:head" ><A NAME="v%3Ahead" ></A ></A ><B >head</B > :: <A HREF="Data-Text.html#t%3AText" >Text</A > -> <A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Char.html#t%3AChar" >Char</A ></TD ><TD CLASS="declbut" ><A HREF="src/Data-Text.html#head" >Source</A ></TD ></TR ></TABLE ></TD ></TR ><TR ><TD CLASS="doc" ><EM >O(1)</EM > Returns the first character of a <TT ><A HREF="Data-Text.html#t%3AText" >Text</A ></TT >, which must be non-empty. Subject to fusion. </TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="topdecl" ><TABLE CLASS="declbar" ><TR ><TD CLASS="declname" ><A NAME="v:last" ><A NAME="v%3Alast" ></A ></A ><B >last</B > :: <A HREF="Data-Text.html#t%3AText" >Text</A > -> <A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Char.html#t%3AChar" >Char</A ></TD ><TD CLASS="declbut" ><A HREF="src/Data-Text.html#last" >Source</A ></TD ></TR ></TABLE ></TD ></TR ><TR ><TD CLASS="doc" ><EM >O(1)</EM > Returns the last character of a <TT ><A HREF="Data-Text.html#t%3AText" >Text</A ></TT >, which must be non-empty. Subject to fusion. </TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="topdecl" ><TABLE CLASS="declbar" ><TR ><TD CLASS="declname" ><A NAME="v:tail" ><A NAME="v%3Atail" ></A ></A ><B >tail</B > :: <A HREF="Data-Text.html#t%3AText" >Text</A > -> <A HREF="Data-Text.html#t%3AText" >Text</A ></TD ><TD CLASS="declbut" ><A HREF="src/Data-Text.html#tail" >Source</A ></TD ></TR ></TABLE ></TD ></TR ><TR ><TD CLASS="doc" ><EM >O(1)</EM > Returns all characters after the head of a <TT ><A HREF="Data-Text.html#t%3AText" >Text</A ></TT >, which must be non-empty. Subject to fusion. </TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="topdecl" ><TABLE CLASS="declbar" ><TR ><TD CLASS="declname" ><A NAME="v:init" ><A NAME="v%3Ainit" ></A ></A ><B >init</B > :: <A HREF="Data-Text.html#t%3AText" >Text</A > -> <A HREF="Data-Text.html#t%3AText" >Text</A ></TD ><TD CLASS="declbut" ><A HREF="src/Data-Text.html#init" >Source</A ></TD ></TR ></TABLE ></TD ></TR ><TR ><TD CLASS="doc" ><EM >O(1)</EM > Returns all but the last character of a <TT ><A HREF="Data-Text.html#t%3AText" >Text</A ></TT >, which must be non-empty. Subject to fusion. </TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="topdecl" ><TABLE CLASS="declbar" ><TR ><TD CLASS="declname" ><A NAME="v:null" ><A NAME="v%3Anull" ></A ></A ><B >null</B > :: <A HREF="Data-Text.html#t%3AText" >Text</A > -> <A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Bool.html#t%3ABool" >Bool</A ></TD ><TD CLASS="declbut" ><A HREF="src/Data-Text.html#null" >Source</A ></TD ></TR ></TABLE ></TD ></TR ><TR ><TD CLASS="doc" ><EM >O(1)</EM > Tests whether a <TT ><A HREF="Data-Text.html#t%3AText" >Text</A ></TT > is empty or not. Subject to fusion. </TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="topdecl" ><TABLE CLASS="declbar" ><TR ><TD CLASS="declname" ><A NAME="v:length" ><A NAME="v%3Alength" ></A ></A ><B >length</B > :: <A HREF="Data-Text.html#t%3AText" >Text</A > -> <A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Int.html#t%3AInt" >Int</A ></TD ><TD CLASS="declbut" ><A HREF="src/Data-Text.html#length" >Source</A ></TD ></TR ></TABLE ></TD ></TR ><TR ><TD CLASS="doc" ><EM >O(n)</EM > Returns the number of characters in a <TT ><A HREF="Data-Text.html#t%3AText" >Text</A ></TT >. Subject to fusion. </TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="topdecl" ><TABLE CLASS="declbar" ><TR ><TD CLASS="declname" ><A NAME="v:compareLength" ><A NAME="v%3AcompareLength" ></A ></A ><B >compareLength</B > :: <A HREF="Data-Text.html#t%3AText" >Text</A > -> <A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Int.html#t%3AInt" >Int</A > -> <A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Ord.html#t%3AOrdering" >Ordering</A ></TD ><TD CLASS="declbut" ><A HREF="src/Data-Text.html#compareLength" >Source</A ></TD ></TR ></TABLE ></TD ></TR ><TR ><TD CLASS="doc" ><P ><EM >O(n)</EM > Compare the count of characters in a <TT ><A HREF="Data-Text.html#t%3AText" >Text</A ></TT > to a number. Subject to fusion. </P ><P >This function gives the same answer as comparing against the result of <TT ><A HREF="Data-Text.html#v%3Alength" >length</A ></TT >, but can short circuit if the count of characters is greater than the number, and hence be more efficient. </P ></TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="section1" ><A NAME="6" ><A NAME="6" >Transformations </A ></A ></TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="topdecl" ><TABLE CLASS="declbar" ><TR ><TD CLASS="declname" ><A NAME="v:map" ><A NAME="v%3Amap" ></A ></A ><B >map</B > :: (<A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Char.html#t%3AChar" >Char</A > -> <A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Char.html#t%3AChar" >Char</A >) -> <A HREF="Data-Text.html#t%3AText" >Text</A > -> <A HREF="Data-Text.html#t%3AText" >Text</A ></TD ><TD CLASS="declbut" ><A HREF="src/Data-Text.html#map" >Source</A ></TD ></TR ></TABLE ></TD ></TR ><TR ><TD CLASS="doc" ><EM >O(n)</EM > <TT ><A HREF="Data-Text.html#v%3Amap" >map</A ></TT > <TT >f</TT > <TT >t</TT > is the <TT ><A HREF="Data-Text.html#t%3AText" >Text</A ></TT > obtained by applying <TT >f</TT > to each element of <TT >t</TT >. Subject to fusion. </TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="topdecl" ><TABLE CLASS="declbar" ><TR ><TD CLASS="declname" ><A NAME="v:intercalate" ><A NAME="v%3Aintercalate" ></A ></A ><B >intercalate</B > :: <A HREF="Data-Text.html#t%3AText" >Text</A > -> [<A HREF="Data-Text.html#t%3AText" >Text</A >] -> <A HREF="Data-Text.html#t%3AText" >Text</A ></TD ><TD CLASS="declbut" ><A HREF="src/Data-Text.html#intercalate" >Source</A ></TD ></TR ></TABLE ></TD ></TR ><TR ><TD CLASS="doc" ><EM >O(n)</EM > The <TT ><A HREF="Data-Text.html#v%3Aintercalate" >intercalate</A ></TT > function takes a <TT ><A HREF="Data-Text.html#t%3AText" >Text</A ></TT > and a list of <TT ><A HREF="Data-Text.html#t%3AText" >Text</A ></TT >s and concatenates the list after interspersing the first argument between each element of the list. </TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="topdecl" ><TABLE CLASS="declbar" ><TR ><TD CLASS="declname" ><A NAME="v:intersperse" ><A NAME="v%3Aintersperse" ></A ></A ><B >intersperse</B > :: <A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Char.html#t%3AChar" >Char</A > -> <A HREF="Data-Text.html#t%3AText" >Text</A > -> <A HREF="Data-Text.html#t%3AText" >Text</A ></TD ><TD CLASS="declbut" ><A HREF="src/Data-Text.html#intersperse" >Source</A ></TD ></TR ></TABLE ></TD ></TR ><TR ><TD CLASS="doc" ><EM >O(n)</EM > The <TT ><A HREF="Data-Text.html#v%3Aintersperse" >intersperse</A ></TT > function takes a character and places it between the characters of a <TT ><A HREF="Data-Text.html#t%3AText" >Text</A ></TT >. Subject to fusion. </TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="topdecl" ><TABLE CLASS="declbar" ><TR ><TD CLASS="declname" ><A NAME="v:transpose" ><A NAME="v%3Atranspose" ></A ></A ><B >transpose</B > :: [<A HREF="Data-Text.html#t%3AText" >Text</A >] -> [<A HREF="Data-Text.html#t%3AText" >Text</A >]</TD ><TD CLASS="declbut" ><A HREF="src/Data-Text.html#transpose" >Source</A ></TD ></TR ></TABLE ></TD ></TR ><TR ><TD CLASS="doc" ><EM >O(n)</EM > The <TT ><A HREF="Data-Text.html#v%3Atranspose" >transpose</A ></TT > function transposes the rows and columns of its <TT ><A HREF="Data-Text.html#t%3AText" >Text</A ></TT > argument. Note that this function uses <TT ><A HREF="Data-Text.html#v%3Apack" >pack</A ></TT >, <TT ><A HREF="Data-Text.html#v%3Aunpack" >unpack</A ></TT >, and the list version of transpose, and is thus not very efficient. </TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="topdecl" ><TABLE CLASS="declbar" ><TR ><TD CLASS="declname" ><A NAME="v:reverse" ><A NAME="v%3Areverse" ></A ></A ><B >reverse</B > :: <A HREF="Data-Text.html#t%3AText" >Text</A > -> <A HREF="Data-Text.html#t%3AText" >Text</A ></TD ><TD CLASS="declbut" ><A HREF="src/Data-Text.html#reverse" >Source</A ></TD ></TR ></TABLE ></TD ></TR ><TR ><TD CLASS="doc" ><EM >O(n)</EM > Reverse the characters of a string. Subject to fusion. </TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="topdecl" ><TABLE CLASS="declbar" ><TR ><TD CLASS="declname" ><A NAME="v:replace" ><A NAME="v%3Areplace" ></A ></A ><B >replace</B ></TD ><TD CLASS="declbut" ><A HREF="src/Data-Text.html#replace" >Source</A ></TD ></TR ></TABLE ></TD ></TR ><TR ><TD CLASS="body" ><TABLE CLASS="vanilla" CELLSPACING="0" CELLPADDING="0" ><TR ><TD CLASS="arg" >:: <A HREF="Data-Text.html#t%3AText" >Text</A ></TD ><TD CLASS="rdoc" >Text to search for </TD ></TR ><TR ><TD CLASS="arg" >-> <A HREF="Data-Text.html#t%3AText" >Text</A ></TD ><TD CLASS="rdoc" >Replacement text </TD ></TR ><TR ><TD CLASS="arg" >-> <A HREF="Data-Text.html#t%3AText" >Text</A ></TD ><TD CLASS="rdoc" >Input text </TD ></TR ><TR ><TD CLASS="arg" >-> <A HREF="Data-Text.html#t%3AText" >Text</A ></TD ><TD CLASS="rdoc" ></TD ></TR ><TR ><TD CLASS="ndoc" COLSPAN="2" ><P ><EM >O(m+n)</EM > Replace every occurrence of one substring with another. </P ><P >In (unlikely) bad cases, this function's time complexity degrades towards <EM >O(n*m)</EM >. </P ></TD ></TR ></TABLE ></TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="section2" ><A NAME="7" ><A NAME="7" >Case conversion </A ></A ></TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="doc" ><P >When case converting <TT ><A HREF="Data-Text.html#t%3AText" >Text</A ></TT > values, do not use combinators like <TT >map toUpper</TT > to case convert each character of a string individually, as this gives incorrect results according to the rules of some writing systems. The whole-string case conversion functions from this module, such as <TT >toUpper</TT >, obey the correct case conversion rules. As a result, these functions may map one input character to two or three output characters. For examples, see the documentation of each function. </P ><P ><EM >Note</EM >: In some languages, case conversion is a locale- and context-dependent operation. The case conversion functions in this module are <EM >not</EM > locale sensitive. Programs that require locale sensitivity should use appropriate versions of the case mapping functions from the <TT >text-icu</TT > package. </P ></TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="topdecl" ><TABLE CLASS="declbar" ><TR ><TD CLASS="declname" ><A NAME="v:toCaseFold" ><A NAME="v%3AtoCaseFold" ></A ></A ><B >toCaseFold</B > :: <A HREF="Data-Text.html#t%3AText" >Text</A > -> <A HREF="Data-Text.html#t%3AText" >Text</A ></TD ><TD CLASS="declbut" ><A HREF="src/Data-Text.html#toCaseFold" >Source</A ></TD ></TR ></TABLE ></TD ></TR ><TR ><TD CLASS="doc" ><P ><EM >O(n)</EM > Convert a string to folded case. This function is mainly useful for performing caseless (also known as case insensitive) string comparisons. </P ><P >A string <TT >x</TT > is a caseless match for a string <TT >y</TT > if and only if: </P ><PRE >toCaseFold x == toCaseFold y</PRE ><P >The result string may be longer than the input string, and may differ from applying <TT ><A HREF="Data-Text.html#v%3AtoLower" >toLower</A ></TT > to the input string. For instance, the Armenian small ligature "ﬓ" (men now, U+FB13) is case folded to the sequence "մ" (men, U+0574) followed by "ն" (now, U+0576), while the Greek "µ" (micro sign, U+00B5) is case folded to "μ" (small letter mu, U+03BC) instead of itself. </P ></TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="topdecl" ><TABLE CLASS="declbar" ><TR ><TD CLASS="declname" ><A NAME="v:toLower" ><A NAME="v%3AtoLower" ></A ></A ><B >toLower</B > :: <A HREF="Data-Text.html#t%3AText" >Text</A > -> <A HREF="Data-Text.html#t%3AText" >Text</A ></TD ><TD CLASS="declbut" ><A HREF="src/Data-Text.html#toLower" >Source</A ></TD ></TR ></TABLE ></TD ></TR ><TR ><TD CLASS="doc" ><EM >O(n)</EM > Convert a string to lower case, using simple case conversion. The result string may be longer than the input string. For instance, "İ" (Latin capital letter I with dot above, U+0130) maps to the sequence "i" (Latin small letter i, U+0069) followed by " ̇" (combining dot above, U+0307). </TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="topdecl" ><TABLE CLASS="declbar" ><TR ><TD CLASS="declname" ><A NAME="v:toUpper" ><A NAME="v%3AtoUpper" ></A ></A ><B >toUpper</B > :: <A HREF="Data-Text.html#t%3AText" >Text</A > -> <A HREF="Data-Text.html#t%3AText" >Text</A ></TD ><TD CLASS="declbut" ><A HREF="src/Data-Text.html#toUpper" >Source</A ></TD ></TR ></TABLE ></TD ></TR ><TR ><TD CLASS="doc" ><EM >O(n)</EM > Convert a string to upper case, using simple case conversion. The result string may be longer than the input string. For instance, the German "ß" (eszett, U+00DF) maps to the two-letter sequence "SS". </TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="section2" ><A NAME="8" ><A NAME="8" >Justification </A ></A ></TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="topdecl" ><TABLE CLASS="declbar" ><TR ><TD CLASS="declname" ><A NAME="v:justifyLeft" ><A NAME="v%3AjustifyLeft" ></A ></A ><B >justifyLeft</B > :: <A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Int.html#t%3AInt" >Int</A > -> <A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Char.html#t%3AChar" >Char</A > -> <A HREF="Data-Text.html#t%3AText" >Text</A > -> <A HREF="Data-Text.html#t%3AText" >Text</A ></TD ><TD CLASS="declbut" ><A HREF="src/Data-Text.html#justifyLeft" >Source</A ></TD ></TR ></TABLE ></TD ></TR ><TR ><TD CLASS="doc" ><P ><EM >O(n)</EM > Left-justify a string to the given length, using the specified fill character on the right. Subject to fusion. Examples: </P ><PRE > justifyLeft 7 'x' "foo" == "fooxxxx" justifyLeft 3 'x' "foobar" == "foobar" </PRE ></TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="topdecl" ><TABLE CLASS="declbar" ><TR ><TD CLASS="declname" ><A NAME="v:justifyRight" ><A NAME="v%3AjustifyRight" ></A ></A ><B >justifyRight</B > :: <A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Int.html#t%3AInt" >Int</A > -> <A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Char.html#t%3AChar" >Char</A > -> <A HREF="Data-Text.html#t%3AText" >Text</A > -> <A HREF="Data-Text.html#t%3AText" >Text</A ></TD ><TD CLASS="declbut" ><A HREF="src/Data-Text.html#justifyRight" >Source</A ></TD ></TR ></TABLE ></TD ></TR ><TR ><TD CLASS="doc" ><P ><EM >O(n)</EM > Right-justify a string to the given length, using the specified fill character on the left. Examples: </P ><PRE > justifyRight 7 'x' "bar" == "xxxxbar" justifyRight 3 'x' "foobar" == "foobar" </PRE ></TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="topdecl" ><TABLE CLASS="declbar" ><TR ><TD CLASS="declname" ><A NAME="v:center" ><A NAME="v%3Acenter" ></A ></A ><B >center</B > :: <A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Int.html#t%3AInt" >Int</A > -> <A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Char.html#t%3AChar" >Char</A > -> <A HREF="Data-Text.html#t%3AText" >Text</A > -> <A HREF="Data-Text.html#t%3AText" >Text</A ></TD ><TD CLASS="declbut" ><A HREF="src/Data-Text.html#center" >Source</A ></TD ></TR ></TABLE ></TD ></TR ><TR ><TD CLASS="doc" ><P ><EM >O(n)</EM > Center a string to the given length, using the specified fill character on either side. Examples: </P ><PRE > center 8 'x' "HS" = "xxxHSxxx" </PRE ></TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="section1" ><A NAME="9" ><A NAME="9" >Folds </A ></A ></TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="topdecl" ><TABLE CLASS="declbar" ><TR ><TD CLASS="declname" ><A NAME="v:foldl" ><A NAME="v%3Afoldl" ></A ></A ><B >foldl</B > :: (a -> <A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Char.html#t%3AChar" >Char</A > -> a) -> a -> <A HREF="Data-Text.html#t%3AText" >Text</A > -> a</TD ><TD CLASS="declbut" ><A HREF="src/Data-Text.html#foldl" >Source</A ></TD ></TR ></TABLE ></TD ></TR ><TR ><TD CLASS="doc" ><EM >O(n)</EM > <TT ><A HREF="Data-Text.html#v%3Afoldl" >foldl</A ></TT >, applied to a binary operator, a starting value (typically the left-identity of the operator), and a <TT ><A HREF="Data-Text.html#t%3AText" >Text</A ></TT >, reduces the <TT ><A HREF="Data-Text.html#t%3AText" >Text</A ></TT > using the binary operator, from left to right. Subject to fusion. </TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="topdecl" ><TABLE CLASS="declbar" ><TR ><TD CLASS="declname" ><A NAME="v:foldl'" ><A NAME="v%3Afoldl%27" ></A ></A ><B >foldl'</B > :: (a -> <A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Char.html#t%3AChar" >Char</A > -> a) -> a -> <A HREF="Data-Text.html#t%3AText" >Text</A > -> a</TD ><TD CLASS="declbut" ><A HREF="src/Data-Text.html#foldl%27" >Source</A ></TD ></TR ></TABLE ></TD ></TR ><TR ><TD CLASS="doc" ><EM >O(n)</EM > A strict version of <TT ><A HREF="Data-Text.html#v%3Afoldl" >foldl</A ></TT >. Subject to fusion. </TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="topdecl" ><TABLE CLASS="declbar" ><TR ><TD CLASS="declname" ><A NAME="v:foldl1" ><A NAME="v%3Afoldl1" ></A ></A ><B >foldl1</B > :: (<A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Char.html#t%3AChar" >Char</A > -> <A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Char.html#t%3AChar" >Char</A > -> <A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Char.html#t%3AChar" >Char</A >) -> <A HREF="Data-Text.html#t%3AText" >Text</A > -> <A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Char.html#t%3AChar" >Char</A ></TD ><TD CLASS="declbut" ><A HREF="src/Data-Text.html#foldl1" >Source</A ></TD ></TR ></TABLE ></TD ></TR ><TR ><TD CLASS="doc" ><EM >O(n)</EM > A variant of <TT ><A HREF="Data-Text.html#v%3Afoldl" >foldl</A ></TT > that has no starting value argument, and thus must be applied to a non-empty <TT ><A HREF="Data-Text.html#t%3AText" >Text</A ></TT >. Subject to fusion. </TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="topdecl" ><TABLE CLASS="declbar" ><TR ><TD CLASS="declname" ><A NAME="v:foldl1'" ><A NAME="v%3Afoldl1%27" ></A ></A ><B >foldl1'</B > :: (<A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Char.html#t%3AChar" >Char</A > -> <A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Char.html#t%3AChar" >Char</A > -> <A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Char.html#t%3AChar" >Char</A >) -> <A HREF="Data-Text.html#t%3AText" >Text</A > -> <A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Char.html#t%3AChar" >Char</A ></TD ><TD CLASS="declbut" ><A HREF="src/Data-Text.html#foldl1%27" >Source</A ></TD ></TR ></TABLE ></TD ></TR ><TR ><TD CLASS="doc" ><EM >O(n)</EM > A strict version of <TT ><A HREF="Data-Text.html#v%3Afoldl1" >foldl1</A ></TT >. Subject to fusion. </TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="topdecl" ><TABLE CLASS="declbar" ><TR ><TD CLASS="declname" ><A NAME="v:foldr" ><A NAME="v%3Afoldr" ></A ></A ><B >foldr</B > :: (<A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Char.html#t%3AChar" >Char</A > -> a -> a) -> a -> <A HREF="Data-Text.html#t%3AText" >Text</A > -> a</TD ><TD CLASS="declbut" ><A HREF="src/Data-Text.html#foldr" >Source</A ></TD ></TR ></TABLE ></TD ></TR ><TR ><TD CLASS="doc" ><EM >O(n)</EM > <TT ><A HREF="Data-Text.html#v%3Afoldr" >foldr</A ></TT >, applied to a binary operator, a starting value (typically the right-identity of the operator), and a <TT ><A HREF="Data-Text.html#t%3AText" >Text</A ></TT >, reduces the <TT ><A HREF="Data-Text.html#t%3AText" >Text</A ></TT > using the binary operator, from right to left. Subject to fusion. </TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="topdecl" ><TABLE CLASS="declbar" ><TR ><TD CLASS="declname" ><A NAME="v:foldr1" ><A NAME="v%3Afoldr1" ></A ></A ><B >foldr1</B > :: (<A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Char.html#t%3AChar" >Char</A > -> <A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Char.html#t%3AChar" >Char</A > -> <A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Char.html#t%3AChar" >Char</A >) -> <A HREF="Data-Text.html#t%3AText" >Text</A > -> <A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Char.html#t%3AChar" >Char</A ></TD ><TD CLASS="declbut" ><A HREF="src/Data-Text.html#foldr1" >Source</A ></TD ></TR ></TABLE ></TD ></TR ><TR ><TD CLASS="doc" ><EM >O(n)</EM > A variant of <TT ><A HREF="Data-Text.html#v%3Afoldr" >foldr</A ></TT > that has no starting value argument, and thust must be applied to a non-empty <TT ><A HREF="Data-Text.html#t%3AText" >Text</A ></TT >. Subject to fusion. </TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="section2" ><A NAME="10" ><A NAME="10" >Special folds </A ></A ></TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="topdecl" ><TABLE CLASS="declbar" ><TR ><TD CLASS="declname" ><A NAME="v:concat" ><A NAME="v%3Aconcat" ></A ></A ><B >concat</B > :: [<A HREF="Data-Text.html#t%3AText" >Text</A >] -> <A HREF="Data-Text.html#t%3AText" >Text</A ></TD ><TD CLASS="declbut" ><A HREF="src/Data-Text.html#concat" >Source</A ></TD ></TR ></TABLE ></TD ></TR ><TR ><TD CLASS="doc" ><EM >O(n)</EM > Concatenate a list of <TT ><A HREF="Data-Text.html#t%3AText" >Text</A ></TT >s. </TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="topdecl" ><TABLE CLASS="declbar" ><TR ><TD CLASS="declname" ><A NAME="v:concatMap" ><A NAME="v%3AconcatMap" ></A ></A ><B >concatMap</B > :: (<A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Char.html#t%3AChar" >Char</A > -> <A HREF="Data-Text.html#t%3AText" >Text</A >) -> <A HREF="Data-Text.html#t%3AText" >Text</A > -> <A HREF="Data-Text.html#t%3AText" >Text</A ></TD ><TD CLASS="declbut" ><A HREF="src/Data-Text.html#concatMap" >Source</A ></TD ></TR ></TABLE ></TD ></TR ><TR ><TD CLASS="doc" ><EM >O(n)</EM > Map a function over a <TT ><A HREF="Data-Text.html#t%3AText" >Text</A ></TT > that results in a <TT ><A HREF="Data-Text.html#t%3AText" >Text</A ></TT >, and concatenate the results. </TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="topdecl" ><TABLE CLASS="declbar" ><TR ><TD CLASS="declname" ><A NAME="v:any" ><A NAME="v%3Aany" ></A ></A ><B >any</B > :: (<A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Char.html#t%3AChar" >Char</A > -> <A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Bool.html#t%3ABool" >Bool</A >) -> <A HREF="Data-Text.html#t%3AText" >Text</A > -> <A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Bool.html#t%3ABool" >Bool</A ></TD ><TD CLASS="declbut" ><A HREF="src/Data-Text.html#any" >Source</A ></TD ></TR ></TABLE ></TD ></TR ><TR ><TD CLASS="doc" ><EM >O(n)</EM > <TT ><A HREF="Data-Text.html#v%3Aany" >any</A ></TT > <TT >p</TT > <TT >t</TT > determines whether any character in the <TT ><A HREF="Data-Text.html#t%3AText" >Text</A ></TT > <TT >t</TT > satisifes the predicate <TT >p</TT >. Subject to fusion. </TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="topdecl" ><TABLE CLASS="declbar" ><TR ><TD CLASS="declname" ><A NAME="v:all" ><A NAME="v%3Aall" ></A ></A ><B >all</B > :: (<A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Char.html#t%3AChar" >Char</A > -> <A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Bool.html#t%3ABool" >Bool</A >) -> <A HREF="Data-Text.html#t%3AText" >Text</A > -> <A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Bool.html#t%3ABool" >Bool</A ></TD ><TD CLASS="declbut" ><A HREF="src/Data-Text.html#all" >Source</A ></TD ></TR ></TABLE ></TD ></TR ><TR ><TD CLASS="doc" ><EM >O(n)</EM > <TT ><A HREF="Data-Text.html#v%3Aall" >all</A ></TT > <TT >p</TT > <TT >t</TT > determines whether all characters in the <TT ><A HREF="Data-Text.html#t%3AText" >Text</A ></TT > <TT >t</TT > satisify the predicate <TT >p</TT >. Subject to fusion. </TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="topdecl" ><TABLE CLASS="declbar" ><TR ><TD CLASS="declname" ><A NAME="v:maximum" ><A NAME="v%3Amaximum" ></A ></A ><B >maximum</B > :: <A HREF="Data-Text.html#t%3AText" >Text</A > -> <A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Char.html#t%3AChar" >Char</A ></TD ><TD CLASS="declbut" ><A HREF="src/Data-Text.html#maximum" >Source</A ></TD ></TR ></TABLE ></TD ></TR ><TR ><TD CLASS="doc" ><EM >O(n)</EM > <TT ><A HREF="Data-Text.html#v%3Amaximum" >maximum</A ></TT > returns the maximum value from a <TT ><A HREF="Data-Text.html#t%3AText" >Text</A ></TT >, which must be non-empty. Subject to fusion. </TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="topdecl" ><TABLE CLASS="declbar" ><TR ><TD CLASS="declname" ><A NAME="v:minimum" ><A NAME="v%3Aminimum" ></A ></A ><B >minimum</B > :: <A HREF="Data-Text.html#t%3AText" >Text</A > -> <A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Char.html#t%3AChar" >Char</A ></TD ><TD CLASS="declbut" ><A HREF="src/Data-Text.html#minimum" >Source</A ></TD ></TR ></TABLE ></TD ></TR ><TR ><TD CLASS="doc" ><EM >O(n)</EM > <TT ><A HREF="Data-Text.html#v%3Aminimum" >minimum</A ></TT > returns the minimum value from a <TT ><A HREF="Data-Text.html#t%3AText" >Text</A ></TT >, which must be non-empty. Subject to fusion. </TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="section1" ><A NAME="11" ><A NAME="11" >Construction </A ></A ></TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="section2" ><A NAME="12" ><A NAME="12" >Scans </A ></A ></TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="topdecl" ><TABLE CLASS="declbar" ><TR ><TD CLASS="declname" ><A NAME="v:scanl" ><A NAME="v%3Ascanl" ></A ></A ><B >scanl</B > :: (<A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Char.html#t%3AChar" >Char</A > -> <A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Char.html#t%3AChar" >Char</A > -> <A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Char.html#t%3AChar" >Char</A >) -> <A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Char.html#t%3AChar" >Char</A > -> <A HREF="Data-Text.html#t%3AText" >Text</A > -> <A HREF="Data-Text.html#t%3AText" >Text</A ></TD ><TD CLASS="declbut" ><A HREF="src/Data-Text.html#scanl" >Source</A ></TD ></TR ></TABLE ></TD ></TR ><TR ><TD CLASS="doc" ><P ><EM >O(n)</EM > <TT ><A HREF="Data-Text.html#v%3Ascanl" >scanl</A ></TT > is similar to <TT ><A HREF="Data-Text.html#v%3Afoldl" >foldl</A ></TT >, but returns a list of successive reduced values from the left. Subject to fusion. </P ><PRE > scanl f z [x1, x2, ...] == [z, z `f` x1, (z `f` x1) `f` x2, ...] </PRE ><P >Note that </P ><PRE > last (scanl f z xs) == foldl f z xs. </PRE ></TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="topdecl" ><TABLE CLASS="declbar" ><TR ><TD CLASS="declname" ><A NAME="v:scanl1" ><A NAME="v%3Ascanl1" ></A ></A ><B >scanl1</B > :: (<A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Char.html#t%3AChar" >Char</A > -> <A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Char.html#t%3AChar" >Char</A > -> <A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Char.html#t%3AChar" >Char</A >) -> <A HREF="Data-Text.html#t%3AText" >Text</A > -> <A HREF="Data-Text.html#t%3AText" >Text</A ></TD ><TD CLASS="declbut" ><A HREF="src/Data-Text.html#scanl1" >Source</A ></TD ></TR ></TABLE ></TD ></TR ><TR ><TD CLASS="doc" ><P ><EM >O(n)</EM > <TT ><A HREF="Data-Text.html#v%3Ascanl1" >scanl1</A ></TT > is a variant of <TT ><A HREF="Data-Text.html#v%3Ascanl" >scanl</A ></TT > that has no starting value argument. Subject to fusion. </P ><PRE > scanl1 f [x1, x2, ...] == [x1, x1 `f` x2, ...] </PRE ></TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="topdecl" ><TABLE CLASS="declbar" ><TR ><TD CLASS="declname" ><A NAME="v:scanr" ><A NAME="v%3Ascanr" ></A ></A ><B >scanr</B > :: (<A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Char.html#t%3AChar" >Char</A > -> <A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Char.html#t%3AChar" >Char</A > -> <A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Char.html#t%3AChar" >Char</A >) -> <A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Char.html#t%3AChar" >Char</A > -> <A HREF="Data-Text.html#t%3AText" >Text</A > -> <A HREF="Data-Text.html#t%3AText" >Text</A ></TD ><TD CLASS="declbut" ><A HREF="src/Data-Text.html#scanr" >Source</A ></TD ></TR ></TABLE ></TD ></TR ><TR ><TD CLASS="doc" ><P ><EM >O(n)</EM > <TT ><A HREF="Data-Text.html#v%3Ascanr" >scanr</A ></TT > is the right-to-left dual of <TT ><A HREF="Data-Text.html#v%3Ascanl" >scanl</A ></TT >. </P ><PRE > scanr f v == reverse . scanl (flip f) v . reverse </PRE ></TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="topdecl" ><TABLE CLASS="declbar" ><TR ><TD CLASS="declname" ><A NAME="v:scanr1" ><A NAME="v%3Ascanr1" ></A ></A ><B >scanr1</B > :: (<A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Char.html#t%3AChar" >Char</A > -> <A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Char.html#t%3AChar" >Char</A > -> <A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Char.html#t%3AChar" >Char</A >) -> <A HREF="Data-Text.html#t%3AText" >Text</A > -> <A HREF="Data-Text.html#t%3AText" >Text</A ></TD ><TD CLASS="declbut" ><A HREF="src/Data-Text.html#scanr1" >Source</A ></TD ></TR ></TABLE ></TD ></TR ><TR ><TD CLASS="doc" ><EM >O(n)</EM > <TT ><A HREF="Data-Text.html#v%3Ascanr1" >scanr1</A ></TT > is a variant of <TT ><A HREF="Data-Text.html#v%3Ascanr" >scanr</A ></TT > that has no starting value argument. Subject to fusion. </TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="section2" ><A NAME="13" ><A NAME="13" >Accumulating maps </A ></A ></TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="topdecl" ><TABLE CLASS="declbar" ><TR ><TD CLASS="declname" ><A NAME="v:mapAccumL" ><A NAME="v%3AmapAccumL" ></A ></A ><B >mapAccumL</B > :: (a -> <A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Char.html#t%3AChar" >Char</A > -> (a, <A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Char.html#t%3AChar" >Char</A >)) -> a -> <A HREF="Data-Text.html#t%3AText" >Text</A > -> (a, <A HREF="Data-Text.html#t%3AText" >Text</A >)</TD ><TD CLASS="declbut" ><A HREF="src/Data-Text.html#mapAccumL" >Source</A ></TD ></TR ></TABLE ></TD ></TR ><TR ><TD CLASS="doc" ><EM >O(n)</EM > Like a combination of <TT ><A HREF="Data-Text.html#v%3Amap" >map</A ></TT > and <TT ><A HREF="Data-Text.html#v%3Afoldl%27" >foldl'</A ></TT >. Applies a function to each element of a <TT ><A HREF="Data-Text.html#t%3AText" >Text</A ></TT >, passing an accumulating parameter from left to right, and returns a final <TT ><A HREF="Data-Text.html#t%3AText" >Text</A ></TT >. </TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="topdecl" ><TABLE CLASS="declbar" ><TR ><TD CLASS="declname" ><A NAME="v:mapAccumR" ><A NAME="v%3AmapAccumR" ></A ></A ><B >mapAccumR</B > :: (a -> <A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Char.html#t%3AChar" >Char</A > -> (a, <A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Char.html#t%3AChar" >Char</A >)) -> a -> <A HREF="Data-Text.html#t%3AText" >Text</A > -> (a, <A HREF="Data-Text.html#t%3AText" >Text</A >)</TD ><TD CLASS="declbut" ><A HREF="src/Data-Text.html#mapAccumR" >Source</A ></TD ></TR ></TABLE ></TD ></TR ><TR ><TD CLASS="doc" >The <TT ><A HREF="Data-Text.html#v%3AmapAccumR" >mapAccumR</A ></TT > function behaves like a combination of <TT ><A HREF="Data-Text.html#v%3Amap" >map</A ></TT > and a strict <TT ><A HREF="Data-Text.html#v%3Afoldr" >foldr</A ></TT >; it applies a function to each element of a <TT ><A HREF="Data-Text.html#t%3AText" >Text</A ></TT >, passing an accumulating parameter from right to left, and returning a final value of this accumulator together with the new <TT ><A HREF="Data-Text.html#t%3AText" >Text</A ></TT >. </TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="section2" ><A NAME="14" ><A NAME="14" >Generation and unfolding </A ></A ></TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="topdecl" ><TABLE CLASS="declbar" ><TR ><TD CLASS="declname" ><A NAME="v:replicate" ><A NAME="v%3Areplicate" ></A ></A ><B >replicate</B > :: <A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Int.html#t%3AInt" >Int</A > -> <A HREF="Data-Text.html#t%3AText" >Text</A > -> <A HREF="Data-Text.html#t%3AText" >Text</A ></TD ><TD CLASS="declbut" ><A HREF="src/Data-Text.html#replicate" >Source</A ></TD ></TR ></TABLE ></TD ></TR ><TR ><TD CLASS="doc" ><EM >O(n*m)</EM > <TT ><A HREF="Data-Text.html#v%3Areplicate" >replicate</A ></TT > <TT >n</TT > <TT >t</TT > is a <TT ><A HREF="Data-Text.html#t%3AText" >Text</A ></TT > consisting of the input <TT >t</TT > repeated <TT >n</TT > times. </TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="topdecl" ><TABLE CLASS="declbar" ><TR ><TD CLASS="declname" ><A NAME="v:unfoldr" ><A NAME="v%3Aunfoldr" ></A ></A ><B >unfoldr</B > :: (a -> <A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Maybe.html#t%3AMaybe" >Maybe</A > (<A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Char.html#t%3AChar" >Char</A >, a)) -> a -> <A HREF="Data-Text.html#t%3AText" >Text</A ></TD ><TD CLASS="declbut" ><A HREF="src/Data-Text.html#unfoldr" >Source</A ></TD ></TR ></TABLE ></TD ></TR ><TR ><TD CLASS="doc" ><EM >O(n)</EM >, where <TT >n</TT > is the length of the result. The <TT ><A HREF="Data-Text.html#v%3Aunfoldr" >unfoldr</A ></TT > function is analogous to the List <TT ><A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-List.html#v%3Aunfoldr" >unfoldr</A ></TT >. <TT ><A HREF="Data-Text.html#v%3Aunfoldr" >unfoldr</A ></TT > builds a <TT ><A HREF="Data-Text.html#t%3AText" >Text</A ></TT > from a seed value. The function takes the element and returns <TT ><A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Maybe.html#v%3ANothing" >Nothing</A ></TT > if it is done producing the <TT ><A HREF="Data-Text.html#t%3AText" >Text</A ></TT >, otherwise <TT ><A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Maybe.html#v%3AJust" >Just</A ></TT > <TT >(a,b)</TT >. In this case, <TT >a</TT > is the next <TT ><A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Char.html#t%3AChar" >Char</A ></TT > in the string, and <TT >b</TT > is the seed value for further production. Subject to fusion. </TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="topdecl" ><TABLE CLASS="declbar" ><TR ><TD CLASS="declname" ><A NAME="v:unfoldrN" ><A NAME="v%3AunfoldrN" ></A ></A ><B >unfoldrN</B > :: <A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Int.html#t%3AInt" >Int</A > -> (a -> <A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Maybe.html#t%3AMaybe" >Maybe</A > (<A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Char.html#t%3AChar" >Char</A >, a)) -> a -> <A HREF="Data-Text.html#t%3AText" >Text</A ></TD ><TD CLASS="declbut" ><A HREF="src/Data-Text.html#unfoldrN" >Source</A ></TD ></TR ></TABLE ></TD ></TR ><TR ><TD CLASS="doc" ><EM >O(n)</EM > Like <TT ><A HREF="Data-Text.html#v%3Aunfoldr" >unfoldr</A ></TT >, <TT ><A HREF="Data-Text.html#v%3AunfoldrN" >unfoldrN</A ></TT > builds a <TT ><A HREF="Data-Text.html#t%3AText" >Text</A ></TT > from a seed value. However, the length of the result should be limited by the first argument to <TT ><A HREF="Data-Text.html#v%3AunfoldrN" >unfoldrN</A ></TT >. This function is more efficient than <TT ><A HREF="Data-Text.html#v%3Aunfoldr" >unfoldr</A ></TT > when the maximum length of the result is known and correct, otherwise its performance is similar to <TT ><A HREF="Data-Text.html#v%3Aunfoldr" >unfoldr</A ></TT >. Subject to fusion. </TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="section1" ><A NAME="15" ><A NAME="15" >Substrings </A ></A ></TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="section2" ><A NAME="16" ><A NAME="16" >Breaking strings </A ></A ></TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="topdecl" ><TABLE CLASS="declbar" ><TR ><TD CLASS="declname" ><A NAME="v:take" ><A NAME="v%3Atake" ></A ></A ><B >take</B > :: <A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Int.html#t%3AInt" >Int</A > -> <A HREF="Data-Text.html#t%3AText" >Text</A > -> <A HREF="Data-Text.html#t%3AText" >Text</A ></TD ><TD CLASS="declbut" ><A HREF="src/Data-Text.html#take" >Source</A ></TD ></TR ></TABLE ></TD ></TR ><TR ><TD CLASS="doc" ><EM >O(n)</EM > <TT ><A HREF="Data-Text.html#v%3Atake" >take</A ></TT > <TT >n</TT >, applied to a <TT ><A HREF="Data-Text.html#t%3AText" >Text</A ></TT >, returns the prefix of the <TT ><A HREF="Data-Text.html#t%3AText" >Text</A ></TT > of length <TT >n</TT >, or the <TT ><A HREF="Data-Text.html#t%3AText" >Text</A ></TT > itself if <TT >n</TT > is greater than the length of the Text. Subject to fusion. </TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="topdecl" ><TABLE CLASS="declbar" ><TR ><TD CLASS="declname" ><A NAME="v:drop" ><A NAME="v%3Adrop" ></A ></A ><B >drop</B > :: <A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Int.html#t%3AInt" >Int</A > -> <A HREF="Data-Text.html#t%3AText" >Text</A > -> <A HREF="Data-Text.html#t%3AText" >Text</A ></TD ><TD CLASS="declbut" ><A HREF="src/Data-Text.html#drop" >Source</A ></TD ></TR ></TABLE ></TD ></TR ><TR ><TD CLASS="doc" ><EM >O(n)</EM > <TT ><A HREF="Data-Text.html#v%3Adrop" >drop</A ></TT > <TT >n</TT >, applied to a <TT ><A HREF="Data-Text.html#t%3AText" >Text</A ></TT >, returns the suffix of the <TT ><A HREF="Data-Text.html#t%3AText" >Text</A ></TT > after the first <TT >n</TT > characters, or the empty <TT ><A HREF="Data-Text.html#t%3AText" >Text</A ></TT > if <TT >n</TT > is greater than the length of the <TT ><A HREF="Data-Text.html#t%3AText" >Text</A ></TT >. Subject to fusion. </TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="topdecl" ><TABLE CLASS="declbar" ><TR ><TD CLASS="declname" ><A NAME="v:takeWhile" ><A NAME="v%3AtakeWhile" ></A ></A ><B >takeWhile</B > :: (<A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Char.html#t%3AChar" >Char</A > -> <A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Bool.html#t%3ABool" >Bool</A >) -> <A HREF="Data-Text.html#t%3AText" >Text</A > -> <A HREF="Data-Text.html#t%3AText" >Text</A ></TD ><TD CLASS="declbut" ><A HREF="src/Data-Text.html#takeWhile" >Source</A ></TD ></TR ></TABLE ></TD ></TR ><TR ><TD CLASS="doc" ><EM >O(n)</EM > <TT ><A HREF="Data-Text.html#v%3AtakeWhile" >takeWhile</A ></TT >, applied to a predicate <TT >p</TT > and a <TT ><A HREF="Data-Text.html#t%3AText" >Text</A ></TT >, returns the longest prefix (possibly empty) of elements that satisfy <TT >p</TT >. Subject to fusion. </TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="topdecl" ><TABLE CLASS="declbar" ><TR ><TD CLASS="declname" ><A NAME="v:dropWhile" ><A NAME="v%3AdropWhile" ></A ></A ><B >dropWhile</B > :: (<A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Char.html#t%3AChar" >Char</A > -> <A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Bool.html#t%3ABool" >Bool</A >) -> <A HREF="Data-Text.html#t%3AText" >Text</A > -> <A HREF="Data-Text.html#t%3AText" >Text</A ></TD ><TD CLASS="declbut" ><A HREF="src/Data-Text.html#dropWhile" >Source</A ></TD ></TR ></TABLE ></TD ></TR ><TR ><TD CLASS="doc" ><EM >O(n)</EM > <TT ><A HREF="Data-Text.html#v%3AdropWhile" >dropWhile</A ></TT > <TT >p</TT > <TT >t</TT > returns the suffix remaining after <TT ><A HREF="Data-Text.html#v%3AtakeWhile" >takeWhile</A ></TT > <TT >p</TT > <TT >t</TT >. Subject to fusion. </TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="topdecl" ><TABLE CLASS="declbar" ><TR ><TD CLASS="declname" ><A NAME="v:dropWhileEnd" ><A NAME="v%3AdropWhileEnd" ></A ></A ><B >dropWhileEnd</B > :: (<A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Char.html#t%3AChar" >Char</A > -> <A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Bool.html#t%3ABool" >Bool</A >) -> <A HREF="Data-Text.html#t%3AText" >Text</A > -> <A HREF="Data-Text.html#t%3AText" >Text</A ></TD ><TD CLASS="declbut" ><A HREF="src/Data-Text.html#dropWhileEnd" >Source</A ></TD ></TR ></TABLE ></TD ></TR ><TR ><TD CLASS="doc" ><P ><EM >O(n)</EM > <TT ><A HREF="Data-Text.html#v%3AdropWhileEnd" >dropWhileEnd</A ></TT > <TT >p</TT > <TT >t</TT > returns the prefix remaining after dropping characters that fail the predicate <TT >p</TT > from the end of <TT >t</TT >. Subject to fusion. Examples: </P ><PRE > dropWhileEnd (=='.') "foo..." == "foo" </PRE ></TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="topdecl" ><TABLE CLASS="declbar" ><TR ><TD CLASS="declname" ><A NAME="v:dropAround" ><A NAME="v%3AdropAround" ></A ></A ><B >dropAround</B > :: (<A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Char.html#t%3AChar" >Char</A > -> <A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Bool.html#t%3ABool" >Bool</A >) -> <A HREF="Data-Text.html#t%3AText" >Text</A > -> <A HREF="Data-Text.html#t%3AText" >Text</A ></TD ><TD CLASS="declbut" ><A HREF="src/Data-Text.html#dropAround" >Source</A ></TD ></TR ></TABLE ></TD ></TR ><TR ><TD CLASS="doc" ><EM >O(n)</EM > <TT ><A HREF="Data-Text.html#v%3AdropAround" >dropAround</A ></TT > <TT >p</TT > <TT >t</TT > returns the substring remaining after dropping characters that fail the predicate <TT >p</TT > from both the beginning and end of <TT >t</TT >. Subject to fusion. </TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="topdecl" ><TABLE CLASS="declbar" ><TR ><TD CLASS="declname" ><A NAME="v:strip" ><A NAME="v%3Astrip" ></A ></A ><B >strip</B > :: <A HREF="Data-Text.html#t%3AText" >Text</A > -> <A HREF="Data-Text.html#t%3AText" >Text</A ></TD ><TD CLASS="declbut" ><A HREF="src/Data-Text.html#strip" >Source</A ></TD ></TR ></TABLE ></TD ></TR ><TR ><TD CLASS="doc" ><P ><EM >O(n)</EM > Remove leading and trailing white space from a string. Equivalent to: </P ><PRE > dropAround isSpace </PRE ></TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="topdecl" ><TABLE CLASS="declbar" ><TR ><TD CLASS="declname" ><A NAME="v:stripStart" ><A NAME="v%3AstripStart" ></A ></A ><B >stripStart</B > :: <A HREF="Data-Text.html#t%3AText" >Text</A > -> <A HREF="Data-Text.html#t%3AText" >Text</A ></TD ><TD CLASS="declbut" ><A HREF="src/Data-Text.html#stripStart" >Source</A ></TD ></TR ></TABLE ></TD ></TR ><TR ><TD CLASS="doc" ><P ><EM >O(n)</EM > Remove leading white space from a string. Equivalent to: </P ><PRE > dropWhile isSpace </PRE ></TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="topdecl" ><TABLE CLASS="declbar" ><TR ><TD CLASS="declname" ><A NAME="v:stripEnd" ><A NAME="v%3AstripEnd" ></A ></A ><B >stripEnd</B > :: <A HREF="Data-Text.html#t%3AText" >Text</A > -> <A HREF="Data-Text.html#t%3AText" >Text</A ></TD ><TD CLASS="declbut" ><A HREF="src/Data-Text.html#stripEnd" >Source</A ></TD ></TR ></TABLE ></TD ></TR ><TR ><TD CLASS="doc" ><P ><EM >O(n)</EM > Remove trailing white space from a string. Equivalent to: </P ><PRE > dropWhileEnd isSpace </PRE ></TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="topdecl" ><TABLE CLASS="declbar" ><TR ><TD CLASS="declname" ><A NAME="v:splitAt" ><A NAME="v%3AsplitAt" ></A ></A ><B >splitAt</B > :: <A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Int.html#t%3AInt" >Int</A > -> <A HREF="Data-Text.html#t%3AText" >Text</A > -> (<A HREF="Data-Text.html#t%3AText" >Text</A >, <A HREF="Data-Text.html#t%3AText" >Text</A >)</TD ><TD CLASS="declbut" ><A HREF="src/Data-Text.html#splitAt" >Source</A ></TD ></TR ></TABLE ></TD ></TR ><TR ><TD CLASS="doc" ><EM >O(n)</EM > <TT ><A HREF="Data-Text.html#v%3AsplitAt" >splitAt</A ></TT > <TT >n t</TT > returns a pair whose first element is a prefix of <TT >t</TT > of length <TT >n</TT >, and whose second is the remainder of the string. It is equivalent to <TT >(<TT ><A HREF="Data-Text.html#v%3Atake" >take</A ></TT > n t, <TT ><A HREF="Data-Text.html#v%3Adrop" >drop</A ></TT > n t)</TT >. </TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="topdecl" ><TABLE CLASS="declbar" ><TR ><TD CLASS="declname" ><A NAME="v:spanBy" ><A NAME="v%3AspanBy" ></A ></A ><B >spanBy</B > :: (<A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Char.html#t%3AChar" >Char</A > -> <A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Bool.html#t%3ABool" >Bool</A >) -> <A HREF="Data-Text.html#t%3AText" >Text</A > -> (<A HREF="Data-Text.html#t%3AText" >Text</A >, <A HREF="Data-Text.html#t%3AText" >Text</A >)</TD ><TD CLASS="declbut" ><A HREF="src/Data-Text.html#spanBy" >Source</A ></TD ></TR ></TABLE ></TD ></TR ><TR ><TD CLASS="doc" ><EM >O(n)</EM > <TT ><A HREF="Data-Text.html#v%3AspanBy" >spanBy</A ></TT >, applied to a predicate <TT >p</TT > and text <TT >t</TT >, returns a pair whose first element is the longest prefix (possibly empty) of <TT >t</TT > of elements that satisfy <TT >p</TT >, and whose second is the remainder of the list. </TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="topdecl" ><TABLE CLASS="declbar" ><TR ><TD CLASS="declname" ><A NAME="v:break" ><A NAME="v%3Abreak" ></A ></A ><B >break</B > :: <A HREF="Data-Text.html#t%3AText" >Text</A > -> <A HREF="Data-Text.html#t%3AText" >Text</A > -> (<A HREF="Data-Text.html#t%3AText" >Text</A >, <A HREF="Data-Text.html#t%3AText" >Text</A >)</TD ><TD CLASS="declbut" ><A HREF="src/Data-Text.html#break" >Source</A ></TD ></TR ></TABLE ></TD ></TR ><TR ><TD CLASS="doc" ><P ><EM >O(n+m)</EM > Find the first instance of <TT >needle</TT > (which must be non-<TT ><A HREF="Data-Text.html#v%3Anull" >null</A ></TT >) in <TT >haystack</TT >. The first element of the returned tuple is the prefix of <TT >haystack</TT > before <TT >needle</TT > is matched. The second is the remainder of <TT >haystack</TT >, starting with the match. </P ><P >Examples: </P ><PRE > break "::" "a::b::c" ==> ("a", "::b::c") break "/" "foobar" ==> ("foobar", "") </PRE ><P >Laws: </P ><PRE > append prefix match == haystack where (prefix, match) = break needle haystack </PRE ><P >If you need to break a string by a substring repeatedly (e.g. you want to break on every instance of a substring), use <TT ><A HREF="Data-Text.html#v%3Afind" >find</A ></TT > instead, as it has lower startup overhead. </P ><P >In (unlikely) bad cases, this function's time complexity degrades towards <EM >O(n*m)</EM >. </P ></TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="topdecl" ><TABLE CLASS="declbar" ><TR ><TD CLASS="declname" ><A NAME="v:breakEnd" ><A NAME="v%3AbreakEnd" ></A ></A ><B >breakEnd</B > :: <A HREF="Data-Text.html#t%3AText" >Text</A > -> <A HREF="Data-Text.html#t%3AText" >Text</A > -> (<A HREF="Data-Text.html#t%3AText" >Text</A >, <A HREF="Data-Text.html#t%3AText" >Text</A >)</TD ><TD CLASS="declbut" ><A HREF="src/Data-Text.html#breakEnd" >Source</A ></TD ></TR ></TABLE ></TD ></TR ><TR ><TD CLASS="doc" ><P ><EM >O(n+m)</EM > Similar to <TT ><A HREF="Data-Text.html#v%3Abreak" >break</A ></TT >, but searches from the end of the string. </P ><P >The first element of the returned tuple is the prefix of <TT >haystack</TT > up to and including the last match of <TT >needle</TT >. The second is the remainder of <TT >haystack</TT >, following the match. </P ><PRE > breakEnd "::" "a::b::c" ==> ("a::b::", "c") </PRE ></TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="topdecl" ><TABLE CLASS="declbar" ><TR ><TD CLASS="declname" ><A NAME="v:breakBy" ><A NAME="v%3AbreakBy" ></A ></A ><B >breakBy</B > :: (<A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Char.html#t%3AChar" >Char</A > -> <A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Bool.html#t%3ABool" >Bool</A >) -> <A HREF="Data-Text.html#t%3AText" >Text</A > -> (<A HREF="Data-Text.html#t%3AText" >Text</A >, <A HREF="Data-Text.html#t%3AText" >Text</A >)</TD ><TD CLASS="declbut" ><A HREF="src/Data-Text.html#breakBy" >Source</A ></TD ></TR ></TABLE ></TD ></TR ><TR ><TD CLASS="doc" ><EM >O(n)</EM > <TT ><A HREF="Data-Text.html#v%3AbreakBy" >breakBy</A ></TT > is like <TT ><A HREF="Data-Text.html#v%3AspanBy" >spanBy</A ></TT >, but the prefix returned is over elements that fail the predicate <TT >p</TT >. </TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="topdecl" ><TABLE CLASS="declbar" ><TR ><TD CLASS="declname" ><A NAME="v:group" ><A NAME="v%3Agroup" ></A ></A ><B >group</B > :: <A HREF="Data-Text.html#t%3AText" >Text</A > -> [<A HREF="Data-Text.html#t%3AText" >Text</A >]</TD ><TD CLASS="declbut" ><A HREF="src/Data-Text.html#group" >Source</A ></TD ></TR ></TABLE ></TD ></TR ><TR ><TD CLASS="doc" ><EM >O(n)</EM > Group characters in a string by equality. </TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="topdecl" ><TABLE CLASS="declbar" ><TR ><TD CLASS="declname" ><A NAME="v:groupBy" ><A NAME="v%3AgroupBy" ></A ></A ><B >groupBy</B > :: (<A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Char.html#t%3AChar" >Char</A > -> <A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Char.html#t%3AChar" >Char</A > -> <A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Bool.html#t%3ABool" >Bool</A >) -> <A HREF="Data-Text.html#t%3AText" >Text</A > -> [<A HREF="Data-Text.html#t%3AText" >Text</A >]</TD ><TD CLASS="declbut" ><A HREF="src/Data-Text.html#groupBy" >Source</A ></TD ></TR ></TABLE ></TD ></TR ><TR ><TD CLASS="doc" ><EM >O(n)</EM > Group characters in a string according to a predicate. </TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="topdecl" ><TABLE CLASS="declbar" ><TR ><TD CLASS="declname" ><A NAME="v:inits" ><A NAME="v%3Ainits" ></A ></A ><B >inits</B > :: <A HREF="Data-Text.html#t%3AText" >Text</A > -> [<A HREF="Data-Text.html#t%3AText" >Text</A >]</TD ><TD CLASS="declbut" ><A HREF="src/Data-Text.html#inits" >Source</A ></TD ></TR ></TABLE ></TD ></TR ><TR ><TD CLASS="doc" ><EM >O(n)</EM > Return all initial segments of the given <TT ><A HREF="Data-Text.html#t%3AText" >Text</A ></TT >, shortest first. </TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="topdecl" ><TABLE CLASS="declbar" ><TR ><TD CLASS="declname" ><A NAME="v:tails" ><A NAME="v%3Atails" ></A ></A ><B >tails</B > :: <A HREF="Data-Text.html#t%3AText" >Text</A > -> [<A HREF="Data-Text.html#t%3AText" >Text</A >]</TD ><TD CLASS="declbut" ><A HREF="src/Data-Text.html#tails" >Source</A ></TD ></TR ></TABLE ></TD ></TR ><TR ><TD CLASS="doc" ><EM >O(n)</EM > Return all final segments of the given <TT ><A HREF="Data-Text.html#t%3AText" >Text</A ></TT >, longest first. </TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="section2" ><A NAME="17" ><A NAME="17" >Breaking into many substrings </A ></A ></TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="doc" >Splitting functions in this library do not perform character-wise copies to create substrings; they just construct new <TT ><A HREF="Data-Text.html#t%3AText" >Text</A ></TT >s that are slices of the original. </TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="topdecl" ><TABLE CLASS="declbar" ><TR ><TD CLASS="declname" ><A NAME="v:split" ><A NAME="v%3Asplit" ></A ></A ><B >split</B > :: <A HREF="Data-Text.html#t%3AText" >Text</A > -> <A HREF="Data-Text.html#t%3AText" >Text</A > -> [<A HREF="Data-Text.html#t%3AText" >Text</A >]</TD ><TD CLASS="declbut" ><A HREF="src/Data-Text.html#split" >Source</A ></TD ></TR ></TABLE ></TD ></TR ><TR ><TD CLASS="doc" ><P ><EM >O(m+n)</EM > Break a <TT ><A HREF="Data-Text.html#t%3AText" >Text</A ></TT > into pieces separated by the first <TT ><A HREF="Data-Text.html#t%3AText" >Text</A ></TT > argument, consuming the delimiter. An empty delimiter is invalid, and will cause an error to be raised. </P ><P >Examples: </P ><PRE > split "\r\n" "a\r\nb\r\nd\r\ne" == ["a","b","d","e"] split "aaa" "aaaXaaaXaaaXaaa" == ["","X","X","X",""] split "x" "x" == ["",""] </PRE ><P >and </P ><PRE > intercalate s . split s == id split (singleton c) == splitBy (==c) </PRE ><P >In (unlikely) bad cases, this function's time complexity degrades towards <EM >O(n*m)</EM >. </P ></TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="topdecl" ><TABLE CLASS="declbar" ><TR ><TD CLASS="declname" ><A NAME="v:splitBy" ><A NAME="v%3AsplitBy" ></A ></A ><B >splitBy</B > :: (<A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Char.html#t%3AChar" >Char</A > -> <A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Bool.html#t%3ABool" >Bool</A >) -> <A HREF="Data-Text.html#t%3AText" >Text</A > -> [<A HREF="Data-Text.html#t%3AText" >Text</A >]</TD ><TD CLASS="declbut" ><A HREF="src/Data-Text.html#splitBy" >Source</A ></TD ></TR ></TABLE ></TD ></TR ><TR ><TD CLASS="doc" ><P ><EM >O(n)</EM > Splits a <TT ><A HREF="Data-Text.html#t%3AText" >Text</A ></TT > into components delimited by separators, where the predicate returns True for a separator element. The resulting components do not contain the separators. Two adjacent separators result in an empty component in the output. eg. </P ><PRE > splitBy (=='a') "aabbaca" == ["","","bb","c",""] splitBy (=='a') "" == [""] </PRE ></TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="topdecl" ><TABLE CLASS="declbar" ><TR ><TD CLASS="declname" ><A NAME="v:chunksOf" ><A NAME="v%3AchunksOf" ></A ></A ><B >chunksOf</B > :: <A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Int.html#t%3AInt" >Int</A > -> <A HREF="Data-Text.html#t%3AText" >Text</A > -> [<A HREF="Data-Text.html#t%3AText" >Text</A >]</TD ><TD CLASS="declbut" ><A HREF="src/Data-Text.html#chunksOf" >Source</A ></TD ></TR ></TABLE ></TD ></TR ><TR ><TD CLASS="doc" ><P ><EM >O(n)</EM > Splits a <TT ><A HREF="Data-Text.html#t%3AText" >Text</A ></TT > into components of length <TT >k</TT >. The last element may be shorter than the other chunks, depending on the length of the input. Examples: </P ><PRE > chunksOf 3 "foobarbaz" == ["foo","bar","baz"] chunksOf 4 "haskell.org" == ["hask","ell.","org"] </PRE ></TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="section2" ><A NAME="18" ><A NAME="18" >Breaking into lines and words </A ></A ></TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="topdecl" ><TABLE CLASS="declbar" ><TR ><TD CLASS="declname" ><A NAME="v:lines" ><A NAME="v%3Alines" ></A ></A ><B >lines</B > :: <A HREF="Data-Text.html#t%3AText" >Text</A > -> [<A HREF="Data-Text.html#t%3AText" >Text</A >]</TD ><TD CLASS="declbut" ><A HREF="src/Data-Text.html#lines" >Source</A ></TD ></TR ></TABLE ></TD ></TR ><TR ><TD CLASS="doc" ><EM >O(n)</EM > Breaks a <TT ><A HREF="Data-Text.html#t%3AText" >Text</A ></TT > up into a list of <TT ><A HREF="Data-Text.html#t%3AText" >Text</A ></TT >s at newline <TT ><A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Char.html#t%3AChar" >Char</A ></TT >s. The resulting strings do not contain newlines. </TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="topdecl" ><TABLE CLASS="declbar" ><TR ><TD CLASS="declname" ><A NAME="v:words" ><A NAME="v%3Awords" ></A ></A ><B >words</B > :: <A HREF="Data-Text.html#t%3AText" >Text</A > -> [<A HREF="Data-Text.html#t%3AText" >Text</A >]</TD ><TD CLASS="declbut" ><A HREF="src/Data-Text.html#words" >Source</A ></TD ></TR ></TABLE ></TD ></TR ><TR ><TD CLASS="doc" ><EM >O(n)</EM > Breaks a <TT ><A HREF="Data-Text.html#t%3AText" >Text</A ></TT > up into a list of words, delimited by <TT ><A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Char.html#t%3AChar" >Char</A ></TT >s representing white space. </TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="topdecl" ><TABLE CLASS="declbar" ><TR ><TD CLASS="declname" ><A NAME="v:unlines" ><A NAME="v%3Aunlines" ></A ></A ><B >unlines</B > :: [<A HREF="Data-Text.html#t%3AText" >Text</A >] -> <A HREF="Data-Text.html#t%3AText" >Text</A ></TD ><TD CLASS="declbut" ><A HREF="src/Data-Text.html#unlines" >Source</A ></TD ></TR ></TABLE ></TD ></TR ><TR ><TD CLASS="doc" ><EM >O(n)</EM > Joins lines, after appending a terminating newline to each. </TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="topdecl" ><TABLE CLASS="declbar" ><TR ><TD CLASS="declname" ><A NAME="v:unwords" ><A NAME="v%3Aunwords" ></A ></A ><B >unwords</B > :: [<A HREF="Data-Text.html#t%3AText" >Text</A >] -> <A HREF="Data-Text.html#t%3AText" >Text</A ></TD ><TD CLASS="declbut" ><A HREF="src/Data-Text.html#unwords" >Source</A ></TD ></TR ></TABLE ></TD ></TR ><TR ><TD CLASS="doc" ><EM >O(n)</EM > Joins words using single space characters. </TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="section1" ><A NAME="19" ><A NAME="19" >Predicates </A ></A ></TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="topdecl" ><TABLE CLASS="declbar" ><TR ><TD CLASS="declname" ><A NAME="v:isPrefixOf" ><A NAME="v%3AisPrefixOf" ></A ></A ><B >isPrefixOf</B > :: <A HREF="Data-Text.html#t%3AText" >Text</A > -> <A HREF="Data-Text.html#t%3AText" >Text</A > -> <A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Bool.html#t%3ABool" >Bool</A ></TD ><TD CLASS="declbut" ><A HREF="src/Data-Text.html#isPrefixOf" >Source</A ></TD ></TR ></TABLE ></TD ></TR ><TR ><TD CLASS="doc" ><EM >O(n)</EM > The <TT ><A HREF="Data-Text.html#v%3AisPrefixOf" >isPrefixOf</A ></TT > function takes two <TT ><A HREF="Data-Text.html#t%3AText" >Text</A ></TT >s and returns <TT ><A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Bool.html#v%3ATrue" >True</A ></TT > iff the first is a prefix of the second. This function is subject to fusion. </TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="topdecl" ><TABLE CLASS="declbar" ><TR ><TD CLASS="declname" ><A NAME="v:isSuffixOf" ><A NAME="v%3AisSuffixOf" ></A ></A ><B >isSuffixOf</B > :: <A HREF="Data-Text.html#t%3AText" >Text</A > -> <A HREF="Data-Text.html#t%3AText" >Text</A > -> <A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Bool.html#t%3ABool" >Bool</A ></TD ><TD CLASS="declbut" ><A HREF="src/Data-Text.html#isSuffixOf" >Source</A ></TD ></TR ></TABLE ></TD ></TR ><TR ><TD CLASS="doc" ><EM >O(n)</EM > The <TT ><A HREF="Data-Text.html#v%3AisSuffixOf" >isSuffixOf</A ></TT > function takes two <TT ><A HREF="Data-Text.html#t%3AText" >Text</A ></TT >s and returns <TT ><A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Bool.html#v%3ATrue" >True</A ></TT > iff the first is a suffix of the second. </TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="topdecl" ><TABLE CLASS="declbar" ><TR ><TD CLASS="declname" ><A NAME="v:isInfixOf" ><A NAME="v%3AisInfixOf" ></A ></A ><B >isInfixOf</B > :: <A HREF="Data-Text.html#t%3AText" >Text</A > -> <A HREF="Data-Text.html#t%3AText" >Text</A > -> <A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Bool.html#t%3ABool" >Bool</A ></TD ><TD CLASS="declbut" ><A HREF="src/Data-Text.html#isInfixOf" >Source</A ></TD ></TR ></TABLE ></TD ></TR ><TR ><TD CLASS="doc" ><P ><EM >O(n+m)</EM > The <TT ><A HREF="Data-Text.html#v%3AisInfixOf" >isInfixOf</A ></TT > function takes two <TT ><A HREF="Data-Text.html#t%3AText" >Text</A ></TT >s and returns <TT ><A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Bool.html#v%3ATrue" >True</A ></TT > iff the first is contained, wholly and intact, anywhere within the second. </P ><P >In (unlikely) bad cases, this function's time complexity degrades towards <EM >O(n*m)</EM >. </P ></TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="section2" ><A NAME="20" ><A NAME="20" >View patterns </A ></A ></TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="topdecl" ><TABLE CLASS="declbar" ><TR ><TD CLASS="declname" ><A NAME="v:stripPrefix" ><A NAME="v%3AstripPrefix" ></A ></A ><B >stripPrefix</B > :: <A HREF="Data-Text.html#t%3AText" >Text</A > -> <A HREF="Data-Text.html#t%3AText" >Text</A > -> <A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Maybe.html#t%3AMaybe" >Maybe</A > <A HREF="Data-Text.html#t%3AText" >Text</A ></TD ><TD CLASS="declbut" ><A HREF="src/Data-Text.html#stripPrefix" >Source</A ></TD ></TR ></TABLE ></TD ></TR ><TR ><TD CLASS="doc" ><P ><EM >O(n)</EM > Returns the suffix of the second string if its prefix matches the first. </P ><P >Examples: </P ><PRE > stripPrefix "foo" "foobar" == Just "bar" stripPrefix "foo" "quux" == Nothing </PRE ><P >This is particularly useful with the <TT >ViewPatterns</TT > extension to GHC, as follows: </P ><PRE > {-# LANGUAGE ViewPatterns #-} import Data.Text as T fnordLength :: Text -> Int fnordLength (stripPrefix "fnord" -> Just suf) = T.length suf fnordLength _ = -1 </PRE ></TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="topdecl" ><TABLE CLASS="declbar" ><TR ><TD CLASS="declname" ><A NAME="v:stripSuffix" ><A NAME="v%3AstripSuffix" ></A ></A ><B >stripSuffix</B > :: <A HREF="Data-Text.html#t%3AText" >Text</A > -> <A HREF="Data-Text.html#t%3AText" >Text</A > -> <A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Maybe.html#t%3AMaybe" >Maybe</A > <A HREF="Data-Text.html#t%3AText" >Text</A ></TD ><TD CLASS="declbut" ><A HREF="src/Data-Text.html#stripSuffix" >Source</A ></TD ></TR ></TABLE ></TD ></TR ><TR ><TD CLASS="doc" ><P ><EM >O(n)</EM > Returns the prefix of the second string if its suffix matches the first. </P ><P >Examples: </P ><PRE > stripSuffix "bar" "foobar" == Just "foo" stripSuffix "foo" "quux" == Nothing </PRE ><P >This is particularly useful with the <TT >ViewPatterns</TT > extension to GHC, as follows: </P ><PRE > {-# LANGUAGE ViewPatterns #-} import Data.Text as T quuxLength :: Text -> Int quuxLength (stripSuffix "quux" -> Just pre) = T.length pre quuxLength _ = -1 </PRE ></TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="section1" ><A NAME="21" ><A NAME="21" >Searching </A ></A ></TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="topdecl" ><TABLE CLASS="declbar" ><TR ><TD CLASS="declname" ><A NAME="v:filter" ><A NAME="v%3Afilter" ></A ></A ><B >filter</B > :: (<A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Char.html#t%3AChar" >Char</A > -> <A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Bool.html#t%3ABool" >Bool</A >) -> <A HREF="Data-Text.html#t%3AText" >Text</A > -> <A HREF="Data-Text.html#t%3AText" >Text</A ></TD ><TD CLASS="declbut" ><A HREF="src/Data-Text.html#filter" >Source</A ></TD ></TR ></TABLE ></TD ></TR ><TR ><TD CLASS="doc" ><EM >O(n)</EM > <TT ><A HREF="Data-Text.html#v%3Afilter" >filter</A ></TT >, applied to a predicate and a <TT ><A HREF="Data-Text.html#t%3AText" >Text</A ></TT >, returns a <TT ><A HREF="Data-Text.html#t%3AText" >Text</A ></TT > containing those characters that satisfy the predicate. </TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="topdecl" ><TABLE CLASS="declbar" ><TR ><TD CLASS="declname" ><A NAME="v:find" ><A NAME="v%3Afind" ></A ></A ><B >find</B ></TD ><TD CLASS="declbut" ><A HREF="src/Data-Text.html#find" >Source</A ></TD ></TR ></TABLE ></TD ></TR ><TR ><TD CLASS="body" ><TABLE CLASS="vanilla" CELLSPACING="0" CELLPADDING="0" ><TR ><TD CLASS="arg" >:: <A HREF="Data-Text.html#t%3AText" >Text</A ></TD ><TD CLASS="rdoc" ><TT >needle</TT > to search for </TD ></TR ><TR ><TD CLASS="arg" >-> <A HREF="Data-Text.html#t%3AText" >Text</A ></TD ><TD CLASS="rdoc" ><TT >haystack</TT > in which to search </TD ></TR ><TR ><TD CLASS="arg" >-> [(<A HREF="Data-Text.html#t%3AText" >Text</A >, <A HREF="Data-Text.html#t%3AText" >Text</A >)]</TD ><TD CLASS="rdoc" ></TD ></TR ><TR ><TD CLASS="ndoc" COLSPAN="2" ><P ><EM >O(n+m)</EM > Find all non-overlapping instances of <TT >needle</TT > in <TT >haystack</TT >. Each element of the returned list consists of a pair: </P ><UL ><LI > The entire string prior to the <EM >k</EM >th match (i.e. the prefix) </LI ><LI > The <EM >k</EM >th match, followed by the remainder of the string </LI ></UL ><P >Examples: </P ><PRE > find "::" "" ==> [] find "/" "a/b/c/" ==> [("a", "/b/c/"), ("a/b", "/c/"), ("a/b/c", "/")] </PRE ><P >In (unlikely) bad cases, this function's time complexity degrades towards <EM >O(n*m)</EM >. </P ><P >The <TT >needle</TT > parameter may not be empty. </P ></TD ></TR ></TABLE ></TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="topdecl" ><TABLE CLASS="declbar" ><TR ><TD CLASS="declname" ><A NAME="v:findBy" ><A NAME="v%3AfindBy" ></A ></A ><B >findBy</B > :: (<A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Char.html#t%3AChar" >Char</A > -> <A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Bool.html#t%3ABool" >Bool</A >) -> <A HREF="Data-Text.html#t%3AText" >Text</A > -> <A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Maybe.html#t%3AMaybe" >Maybe</A > <A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Char.html#t%3AChar" >Char</A ></TD ><TD CLASS="declbut" ><A HREF="src/Data-Text.html#findBy" >Source</A ></TD ></TR ></TABLE ></TD ></TR ><TR ><TD CLASS="doc" ><EM >O(n)</EM > The <TT ><A HREF="Data-Text.html#v%3AfindBy" >findBy</A ></TT > function takes a predicate and a <TT ><A HREF="Data-Text.html#t%3AText" >Text</A ></TT >, and returns the first element in matching the predicate, or <TT ><A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Maybe.html#v%3ANothing" >Nothing</A ></TT > if there is no such element. </TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="topdecl" ><TABLE CLASS="declbar" ><TR ><TD CLASS="declname" ><A NAME="v:partitionBy" ><A NAME="v%3ApartitionBy" ></A ></A ><B >partitionBy</B > :: (<A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Char.html#t%3AChar" >Char</A > -> <A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Bool.html#t%3ABool" >Bool</A >) -> <A HREF="Data-Text.html#t%3AText" >Text</A > -> (<A HREF="Data-Text.html#t%3AText" >Text</A >, <A HREF="Data-Text.html#t%3AText" >Text</A >)</TD ><TD CLASS="declbut" ><A HREF="src/Data-Text.html#partitionBy" >Source</A ></TD ></TR ></TABLE ></TD ></TR ><TR ><TD CLASS="doc" ><P ><EM >O(n)</EM > The <TT ><A HREF="Data-Text.html#v%3ApartitionBy" >partitionBy</A ></TT > function takes a predicate and a <TT ><A HREF="Data-Text.html#t%3AText" >Text</A ></TT >, and returns the pair of <TT ><A HREF="Data-Text.html#t%3AText" >Text</A ></TT >s with elements which do and do not satisfy the predicate, respectively; i.e. </P ><PRE > partitionBy p t == (filter p t, filter (not . p) t) </PRE ></TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="section1" ><A NAME="22" ><A NAME="22" >Indexing </A ></A ></TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="doc" ><P >If you think of a <TT ><A HREF="Data-Text.html#t%3AText" >Text</A ></TT > value as an array of <TT ><A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Char.html#t%3AChar" >Char</A ></TT > values (which it is not), you run the risk of writing inefficient code. </P ><P >An idiom that is common in some languages is to find the numeric offset of a character or substring, then use that number to split or trim the searched string. With a <TT ><A HREF="Data-Text.html#t%3AText" >Text</A ></TT > value, this approach would require two <EM >O(n)</EM > operations: one to perform the search, and one to operate from wherever the search ended. </P ><P >For example, suppose you have a string that you want to split on the substring <TT >"::"</TT >, such as <TT >"foo::bar::quux"</TT >. Instead of searching for the index of <TT >"::"</TT > and taking the substrings before and after that index, you would instead use <TT >find "::"</TT >. </P ></TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="topdecl" ><TABLE CLASS="declbar" ><TR ><TD CLASS="declname" ><A NAME="v:index" ><A NAME="v%3Aindex" ></A ></A ><B >index</B > :: <A HREF="Data-Text.html#t%3AText" >Text</A > -> <A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Int.html#t%3AInt" >Int</A > -> <A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Char.html#t%3AChar" >Char</A ></TD ><TD CLASS="declbut" ><A HREF="src/Data-Text.html#index" >Source</A ></TD ></TR ></TABLE ></TD ></TR ><TR ><TD CLASS="doc" ><EM >O(n)</EM > <TT ><A HREF="Data-Text.html#t%3AText" >Text</A ></TT > index (subscript) operator, starting from 0. </TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="topdecl" ><TABLE CLASS="declbar" ><TR ><TD CLASS="declname" ><A NAME="v:findIndex" ><A NAME="v%3AfindIndex" ></A ></A ><B >findIndex</B > :: (<A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Char.html#t%3AChar" >Char</A > -> <A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Bool.html#t%3ABool" >Bool</A >) -> <A HREF="Data-Text.html#t%3AText" >Text</A > -> <A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Maybe.html#t%3AMaybe" >Maybe</A > <A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Int.html#t%3AInt" >Int</A ></TD ><TD CLASS="declbut" ><A HREF="src/Data-Text.html#findIndex" >Source</A ></TD ></TR ></TABLE ></TD ></TR ><TR ><TD CLASS="doc" ><EM >O(n)</EM > The <TT ><A HREF="Data-Text.html#v%3AfindIndex" >findIndex</A ></TT > function takes a predicate and a <TT ><A HREF="Data-Text.html#t%3AText" >Text</A ></TT > and returns the index of the first element in the <TT ><A HREF="Data-Text.html#t%3AText" >Text</A ></TT > satisfying the predicate. Subject to fusion. </TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="topdecl" ><TABLE CLASS="declbar" ><TR ><TD CLASS="declname" ><A NAME="v:count" ><A NAME="v%3Acount" ></A ></A ><B >count</B > :: <A HREF="Data-Text.html#t%3AText" >Text</A > -> <A HREF="Data-Text.html#t%3AText" >Text</A > -> <A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Int.html#t%3AInt" >Int</A ></TD ><TD CLASS="declbut" ><A HREF="src/Data-Text.html#count" >Source</A ></TD ></TR ></TABLE ></TD ></TR ><TR ><TD CLASS="doc" ><P ><EM >O(n+m)</EM > The <TT ><A HREF="Data-Text.html#v%3Acount" >count</A ></TT > function returns the number of times the query string appears in the given <TT ><A HREF="Data-Text.html#t%3AText" >Text</A ></TT >. An empty query string is invalid, and will cause an error to be raised. </P ><P >In (unlikely) bad cases, this function's time complexity degrades towards <EM >O(n*m)</EM >. </P ></TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="section1" ><A NAME="23" ><A NAME="23" >Zipping and unzipping </A ></A ></TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="topdecl" ><TABLE CLASS="declbar" ><TR ><TD CLASS="declname" ><A NAME="v:zip" ><A NAME="v%3Azip" ></A ></A ><B >zip</B > :: <A HREF="Data-Text.html#t%3AText" >Text</A > -> <A HREF="Data-Text.html#t%3AText" >Text</A > -> [(<A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Char.html#t%3AChar" >Char</A >, <A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Char.html#t%3AChar" >Char</A >)]</TD ><TD CLASS="declbut" ><A HREF="src/Data-Text.html#zip" >Source</A ></TD ></TR ></TABLE ></TD ></TR ><TR ><TD CLASS="doc" ><EM >O(n)</EM > <TT ><A HREF="Data-Text.html#v%3Azip" >zip</A ></TT > takes two <TT ><A HREF="Data-Text.html#t%3AText" >Text</A ></TT >s and returns a list of corresponding pairs of bytes. If one input <TT ><A HREF="Data-Text.html#t%3AText" >Text</A ></TT > is short, excess elements of the longer <TT ><A HREF="Data-Text.html#t%3AText" >Text</A ></TT > are discarded. This is equivalent to a pair of <TT ><A HREF="Data-Text.html#v%3Aunpack" >unpack</A ></TT > operations. </TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="topdecl" ><TABLE CLASS="declbar" ><TR ><TD CLASS="declname" ><A NAME="v:zipWith" ><A NAME="v%3AzipWith" ></A ></A ><B >zipWith</B > :: (<A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Char.html#t%3AChar" >Char</A > -> <A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Char.html#t%3AChar" >Char</A > -> <A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Char.html#t%3AChar" >Char</A >) -> <A HREF="Data-Text.html#t%3AText" >Text</A > -> <A HREF="Data-Text.html#t%3AText" >Text</A > -> <A HREF="Data-Text.html#t%3AText" >Text</A ></TD ><TD CLASS="declbut" ><A HREF="src/Data-Text.html#zipWith" >Source</A ></TD ></TR ></TABLE ></TD ></TR ><TR ><TD CLASS="doc" ><EM >O(n)</EM > <TT ><A HREF="Data-Text.html#v%3AzipWith" >zipWith</A ></TT > generalises <TT ><A HREF="Data-Text.html#v%3Azip" >zip</A ></TT > by zipping with the function given as the first argument, instead of a tupling function. </TD ></TR ><TR ><TD CLASS="s15" ></TD ></TR ><TR ><TD CLASS="botbar" >Produced by <A HREF="http://www.haskell.org/haddock/" >Haddock</A > version 2.6.1</TD ></TR ></TABLE ></BODY ></HTML >