<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>Data.List.Split</title><link href="ocean.css" rel="stylesheet" type="text/css" title="Ocean" /><script src="haddock-util.js" type="text/javascript"></script><script type="text/javascript">//<![CDATA[ window.onload = function () {pageLoad();setSynopsis("mini_Data-List-Split.html");}; //]]> </script></head><body><div id="package-header"><ul class="links" id="page-menu"><li><a href="src/Data-List-Split.html">Source</a></li><li><a href="index.html">Contents</a></li><li><a href="doc-index.html">Index</a></li></ul><p class="caption">split-0.1.3: Combinator library for splitting lists.</p></div><div id="content"><div id="module-header"><table class="info"><tr><th>Portability</th><td>unportable (GADTs, Rank2Types)</td></tr><tr><th>Stability</th><td>experimental</td></tr><tr><th>Maintainer</th><td>Brent Yorgey <byorgey@gmail.com></td></tr></table><p class="caption">Data.List.Split</p></div><div id="table-of-contents"><p class="caption">Contents</p><ul><li><a href="#g:1">Getting started </a></li><li><a href="#g:2">Convenience functions </a></li><li><a href="#g:3">Other splitting methods </a></li><li><a href="#g:4">Splitting combinators </a><ul><li><a href="#g:5">Basic strategies </a></li><li><a href="#g:6">Strategy transformers </a></li><li><a href="#g:7">Derived combinators </a></li></ul></li></ul></div><div id="description"><p class="caption">Description</p><div class="doc"><p>The <a href="Data-List-Split.html">Data.List.Split</a> module contains a wide range of strategies for splitting lists with respect to some sort of delimiter, mostly implemented through a unified combinator interface. The goal is to be flexible yet simple. Scroll past the Synopsis for usage, examples, and detailed documentation of all exported functions. If you want to learn about the implementation, see <a href="Data-List-Split-Internals.html">Data.List.Split.Internals</a>. </p><p>A darcs repository containing the source (including a module with over 40 QuickCheck properties) can be found at <a href="http://code.haskell.org/~byorgey/code/split">http://code.haskell.org/~byorgey/code/split</a>. </p></div></div><div id="synopsis"><p id="control.syn" class="caption expander" onclick="toggleSection('syn')">Synopsis</p><ul id="section.syn" class="hide" onclick="toggleSection('syn')"><li class="src short"><a href="#v:splitOn">splitOn</a> :: <a href="/usr/share/doc/ghc/html/libraries/base-4.3.1.0/Data-Eq.html#t:Eq">Eq</a> a => [a] -> [a] -> [[a]]</li><li class="src short"><a href="#v:splitOneOf">splitOneOf</a> :: <a href="/usr/share/doc/ghc/html/libraries/base-4.3.1.0/Data-Eq.html#t:Eq">Eq</a> a => [a] -> [a] -> [[a]]</li><li class="src short"><a href="#v:splitWhen">splitWhen</a> :: (a -> <a href="/usr/share/doc/ghc/html/libraries/base-4.3.1.0/Data-Bool.html#t:Bool">Bool</a>) -> [a] -> [[a]]</li><li class="src short"><a href="#v:sepBy">sepBy</a> :: <a href="/usr/share/doc/ghc/html/libraries/base-4.3.1.0/Data-Eq.html#t:Eq">Eq</a> a => [a] -> [a] -> [[a]]</li><li class="src short"><a href="#v:sepByOneOf">sepByOneOf</a> :: <a href="/usr/share/doc/ghc/html/libraries/base-4.3.1.0/Data-Eq.html#t:Eq">Eq</a> a => [a] -> [a] -> [[a]]</li><li class="src short"><a href="#v:endBy">endBy</a> :: <a href="/usr/share/doc/ghc/html/libraries/base-4.3.1.0/Data-Eq.html#t:Eq">Eq</a> a => [a] -> [a] -> [[a]]</li><li class="src short"><a href="#v:endByOneOf">endByOneOf</a> :: <a href="/usr/share/doc/ghc/html/libraries/base-4.3.1.0/Data-Eq.html#t:Eq">Eq</a> a => [a] -> [a] -> [[a]]</li><li class="src short"><a href="#v:unintercalate">unintercalate</a> :: <a href="/usr/share/doc/ghc/html/libraries/base-4.3.1.0/Data-Eq.html#t:Eq">Eq</a> a => [a] -> [a] -> [[a]]</li><li class="src short"><a href="#v:wordsBy">wordsBy</a> :: (a -> <a href="/usr/share/doc/ghc/html/libraries/base-4.3.1.0/Data-Bool.html#t:Bool">Bool</a>) -> [a] -> [[a]]</li><li class="src short"><a href="#v:linesBy">linesBy</a> :: (a -> <a href="/usr/share/doc/ghc/html/libraries/base-4.3.1.0/Data-Bool.html#t:Bool">Bool</a>) -> [a] -> [[a]]</li><li class="src short"><a href="#v:splitEvery">splitEvery</a> :: <a href="/usr/share/doc/ghc/html/libraries/base-4.3.1.0/Data-Int.html#t:Int">Int</a> -> [e] -> [[e]]</li><li class="src short"><a href="#v:chunk">chunk</a> :: <a href="/usr/share/doc/ghc/html/libraries/base-4.3.1.0/Data-Int.html#t:Int">Int</a> -> [e] -> [[e]]</li><li class="src short"><a href="#v:splitPlaces">splitPlaces</a> :: <a href="/usr/share/doc/ghc/html/libraries/base-4.3.1.0/Prelude.html#t:Integral">Integral</a> a => [a] -> [e] -> [[e]]</li><li class="src short"><a href="#v:chop">chop</a> :: ([a] -> (b, [a])) -> [a] -> [b]</li><li class="src short"><span class="keyword">data</span> <a href="#t:Splitter">Splitter</a> a</li><li class="src short"><a href="#v:defaultSplitter">defaultSplitter</a> :: <a href="Data-List-Split.html#t:Splitter">Splitter</a> a</li><li class="src short"><a href="#v:split">split</a> :: <a href="Data-List-Split.html#t:Splitter">Splitter</a> a -> [a] -> [[a]]</li><li class="src short"><a href="#v:oneOf">oneOf</a> :: <a href="/usr/share/doc/ghc/html/libraries/base-4.3.1.0/Data-Eq.html#t:Eq">Eq</a> a => [a] -> <a href="Data-List-Split.html#t:Splitter">Splitter</a> a</li><li class="src short"><a href="#v:onSublist">onSublist</a> :: <a href="/usr/share/doc/ghc/html/libraries/base-4.3.1.0/Data-Eq.html#t:Eq">Eq</a> a => [a] -> <a href="Data-List-Split.html#t:Splitter">Splitter</a> a</li><li class="src short"><a href="#v:whenElt">whenElt</a> :: (a -> <a href="/usr/share/doc/ghc/html/libraries/base-4.3.1.0/Data-Bool.html#t:Bool">Bool</a>) -> <a href="Data-List-Split.html#t:Splitter">Splitter</a> a</li><li class="src short"><a href="#v:dropDelims">dropDelims</a> :: <a href="Data-List-Split.html#t:Splitter">Splitter</a> a -> <a href="Data-List-Split.html#t:Splitter">Splitter</a> a</li><li class="src short"><a href="#v:keepDelimsL">keepDelimsL</a> :: <a href="Data-List-Split.html#t:Splitter">Splitter</a> a -> <a href="Data-List-Split.html#t:Splitter">Splitter</a> a</li><li class="src short"><a href="#v:keepDelimsR">keepDelimsR</a> :: <a href="Data-List-Split.html#t:Splitter">Splitter</a> a -> <a href="Data-List-Split.html#t:Splitter">Splitter</a> a</li><li class="src short"><a href="#v:condense">condense</a> :: <a href="Data-List-Split.html#t:Splitter">Splitter</a> a -> <a href="Data-List-Split.html#t:Splitter">Splitter</a> a</li><li class="src short"><a href="#v:dropInitBlank">dropInitBlank</a> :: <a href="Data-List-Split.html#t:Splitter">Splitter</a> a -> <a href="Data-List-Split.html#t:Splitter">Splitter</a> a</li><li class="src short"><a href="#v:dropFinalBlank">dropFinalBlank</a> :: <a href="Data-List-Split.html#t:Splitter">Splitter</a> a -> <a href="Data-List-Split.html#t:Splitter">Splitter</a> a</li><li class="src short"><a href="#v:dropBlanks">dropBlanks</a> :: <a href="Data-List-Split.html#t:Splitter">Splitter</a> a -> <a href="Data-List-Split.html#t:Splitter">Splitter</a> a</li><li class="src short"><a href="#v:startsWith">startsWith</a> :: <a href="/usr/share/doc/ghc/html/libraries/base-4.3.1.0/Data-Eq.html#t:Eq">Eq</a> a => [a] -> <a href="Data-List-Split.html#t:Splitter">Splitter</a> a</li><li class="src short"><a href="#v:startsWithOneOf">startsWithOneOf</a> :: <a href="/usr/share/doc/ghc/html/libraries/base-4.3.1.0/Data-Eq.html#t:Eq">Eq</a> a => [a] -> <a href="Data-List-Split.html#t:Splitter">Splitter</a> a</li><li class="src short"><a href="#v:endsWith">endsWith</a> :: <a href="/usr/share/doc/ghc/html/libraries/base-4.3.1.0/Data-Eq.html#t:Eq">Eq</a> a => [a] -> <a href="Data-List-Split.html#t:Splitter">Splitter</a> a</li><li class="src short"><a href="#v:endsWithOneOf">endsWithOneOf</a> :: <a href="/usr/share/doc/ghc/html/libraries/base-4.3.1.0/Data-Eq.html#t:Eq">Eq</a> a => [a] -> <a href="Data-List-Split.html#t:Splitter">Splitter</a> a</li></ul></div><div id="interface"><h1 id="g:1">Getting started </h1><div class="doc"><p>To get started, you should take a look at the functions <code><a href="Data-List-Split.html#v:splitOn">splitOn</a></code>, <code><a href="Data-List-Split.html#v:splitWhen">splitWhen</a></code>, <code><a href="Data-List-Split.html#v:sepBy">sepBy</a></code>, <code><a href="Data-List-Split.html#v:endBy">endBy</a></code>, <code><a href="Data-List-Split.html#v:splitEvery">splitEvery</a></code>, <code><a href="Data-List-Split.html#v:splitPlaces">splitPlaces</a></code>, and other functions listed in the next two sections. These functions implement various common splitting operations, and one of them will probably do the job 90% of the time. For example: </p><pre> > splitOn "x" "axbxc" ["a","b","c"] > splitOn "x" "axbxcx" ["a","b","c",""] > endBy ";" "foo;bar;baz;" ["foo","bar","baz"] > splitWhen (<0) [1,3,-4,5,7,-9,0,2] [[1,3],[5,7],[0,2]] > splitOneOf ";.," "foo,bar;baz.glurk" ["foo","bar","baz","glurk"] > splitEvery 3 ['a'..'z'] ["abc","def","ghi","jkl","mno","pqr","stu","vwx","yz"] </pre><p>If you want more flexibility, however, you can use the combinator library in terms of which these functions are defined. For more information, skip to the section labeled "Splitting Combinators". </p><p>Note that the goal of this library is to be flexible yet simple. It does not implement any particularly sophisticated list-splitting methods, nor is it tuned for speed. If you find yourself wanting something more complicated or optimized, it probably means you should use a real parsing or regular expression library. </p></div><h1 id="g:2">Convenience functions </h1><div class="doc"><p>These functions implement some common splitting strategies. Note that all of the functions in this section drop delimiters from the final output, since that is a more common use case even though it is not the default. </p></div><div class="top"><p class="src"><a name="v:splitOn" class="def">splitOn</a> :: <a href="/usr/share/doc/ghc/html/libraries/base-4.3.1.0/Data-Eq.html#t:Eq">Eq</a> a => [a] -> [a] -> [[a]]<a href="src/Data-List-Split-Internals.html#splitOn" class="link">Source</a></p><div class="doc"><p>Split on the given sublist. Equivalent to <code><code><a href="Data-List-Split.html#v:split">split</a></code> . <code><a href="Data-List-Split.html#v:dropDelims">dropDelims</a></code> . <code><a href="Data-List-Split.html#v:onSublist">onSublist</a></code></code>. For example: </p><pre> splitOn ".." "a..b...c....d.." == ["a","b",".c","","d",""] </pre></div></div><div class="top"><p class="src"><a name="v:splitOneOf" class="def">splitOneOf</a> :: <a href="/usr/share/doc/ghc/html/libraries/base-4.3.1.0/Data-Eq.html#t:Eq">Eq</a> a => [a] -> [a] -> [[a]]<a href="src/Data-List-Split-Internals.html#splitOneOf" class="link">Source</a></p><div class="doc"><p>Split on any of the given elements. Equivalent to <code><code><a href="Data-List-Split.html#v:split">split</a></code> . <code><a href="Data-List-Split.html#v:dropDelims">dropDelims</a></code> . <code><a href="Data-List-Split.html#v:oneOf">oneOf</a></code></code>. For example: </p><pre> splitOneOf ";.," "foo,bar;baz.glurk" == ["foo","bar","baz","glurk"] </pre></div></div><div class="top"><p class="src"><a name="v:splitWhen" class="def">splitWhen</a> :: (a -> <a href="/usr/share/doc/ghc/html/libraries/base-4.3.1.0/Data-Bool.html#t:Bool">Bool</a>) -> [a] -> [[a]]<a href="src/Data-List-Split-Internals.html#splitWhen" class="link">Source</a></p><div class="doc"><p>Split on elements satisfying the given predicate. Equivalent to <code><code><a href="Data-List-Split.html#v:split">split</a></code> . <code><a href="Data-List-Split.html#v:dropDelims">dropDelims</a></code> . <code><a href="Data-List-Split.html#v:whenElt">whenElt</a></code></code>. For example: </p><pre> splitWhen (<0) [1,3,-4,5,7,-9,0,2] == [[1,3],[5,7],[0,2]] </pre></div></div><div class="top"><p class="src"><a name="v:sepBy" class="def">sepBy</a> :: <a href="/usr/share/doc/ghc/html/libraries/base-4.3.1.0/Data-Eq.html#t:Eq">Eq</a> a => [a] -> [a] -> [[a]]<a href="src/Data-List-Split-Internals.html#sepBy" class="link">Source</a></p><div class="doc"><p>A synonym for <code><a href="Data-List-Split.html#v:splitOn">splitOn</a></code>. </p></div></div><div class="top"><p class="src"><a name="v:sepByOneOf" class="def">sepByOneOf</a> :: <a href="/usr/share/doc/ghc/html/libraries/base-4.3.1.0/Data-Eq.html#t:Eq">Eq</a> a => [a] -> [a] -> [[a]]<a href="src/Data-List-Split-Internals.html#sepByOneOf" class="link">Source</a></p><div class="doc"><p>A synonym for <code><a href="Data-List-Split.html#v:splitOneOf">splitOneOf</a></code>. </p></div></div><div class="top"><p class="src"><a name="v:endBy" class="def">endBy</a> :: <a href="/usr/share/doc/ghc/html/libraries/base-4.3.1.0/Data-Eq.html#t:Eq">Eq</a> a => [a] -> [a] -> [[a]]<a href="src/Data-List-Split-Internals.html#endBy" class="link">Source</a></p><div class="doc"><p>Split into chunks terminated by the given subsequence. Equivalent to <code><code><a href="Data-List-Split.html#v:split">split</a></code> . <code><a href="Data-List-Split.html#v:dropFinalBlank">dropFinalBlank</a></code> . <code><a href="Data-List-Split.html#v:dropDelims">dropDelims</a></code> . <code><a href="Data-List-Split.html#v:onSublist">onSublist</a></code></code>. For example: </p><pre> endBy ";" "foo;bar;baz;" == ["foo","bar","baz"] </pre><p>Note also that the <code><a href="/usr/share/doc/ghc/html/libraries/base-4.3.1.0/Data-List.html#v:lines">lines</a></code> function from <a href="Data-List.html">Data.List</a> is equivalent to <code><code><a href="Data-List-Split.html#v:endBy">endBy</a></code> "\n"</code>. </p></div></div><div class="top"><p class="src"><a name="v:endByOneOf" class="def">endByOneOf</a> :: <a href="/usr/share/doc/ghc/html/libraries/base-4.3.1.0/Data-Eq.html#t:Eq">Eq</a> a => [a] -> [a] -> [[a]]<a href="src/Data-List-Split-Internals.html#endByOneOf" class="link">Source</a></p><div class="doc"><p>Split into chunks terminated by one of the given elements. Equivalent to <code><code><a href="Data-List-Split.html#v:split">split</a></code> . <code><a href="Data-List-Split.html#v:dropFinalBlank">dropFinalBlank</a></code> . <code><a href="Data-List-Split.html#v:dropDelims">dropDelims</a></code> . <code><a href="Data-List-Split.html#v:oneOf">oneOf</a></code></code>. </p></div></div><div class="top"><p class="src"><a name="v:unintercalate" class="def">unintercalate</a> :: <a href="/usr/share/doc/ghc/html/libraries/base-4.3.1.0/Data-Eq.html#t:Eq">Eq</a> a => [a] -> [a] -> [[a]]<a href="src/Data-List-Split-Internals.html#unintercalate" class="link">Source</a></p><div class="doc"><p>A synonym for <code><a href="Data-List-Split.html#v:sepBy">sepBy</a></code> / <code><a href="Data-List-Split.html#v:splitOn">splitOn</a></code>. </p><p>Note that this is the right inverse of the <code>intercalate</code> function from <a href="Data-List.html">Data.List</a>, that is, <code><code>intercalate</code> x . <code><a href="Data-List-Split.html#v:unintercalate">unintercalate</a></code> x == <code><a href="/usr/share/doc/ghc/html/libraries/base-4.3.1.0/Prelude.html#v:id">id</a></code></code>. It is also the case that <code><code><a href="Data-List-Split.html#v:unintercalate">unintercalate</a></code> x . <code>intercalate</code> x</code> is idempotent. <code><code><a href="Data-List-Split.html#v:unintercalate">unintercalate</a></code> x . <code>intercalate</code> x</code> is the identity on certain lists, but it is tricky to state the precise conditions under which this holds. (For example, it is not enough to say that <code>x</code> does not occur in any elements of the input list. Working out why is left as an exercise for the reader.) </p></div></div><div class="top"><p class="src"><a name="v:wordsBy" class="def">wordsBy</a> :: (a -> <a href="/usr/share/doc/ghc/html/libraries/base-4.3.1.0/Data-Bool.html#t:Bool">Bool</a>) -> [a] -> [[a]]<a href="src/Data-List-Split-Internals.html#wordsBy" class="link">Source</a></p><div class="doc"><p>Split into words, with word boundaries indicated by the given predicate. Satisfies <code>words === wordsBy isSpace</code>; equivalent to <code>split . dropBlanks . dropDelims . whenElt</code>. For example: </p><pre> wordsBy (=='x') "dogxxxcatxbirdxx" == ["dog","cat","bird"] </pre></div></div><div class="top"><p class="src"><a name="v:linesBy" class="def">linesBy</a> :: (a -> <a href="/usr/share/doc/ghc/html/libraries/base-4.3.1.0/Data-Bool.html#t:Bool">Bool</a>) -> [a] -> [[a]]<a href="src/Data-List-Split-Internals.html#linesBy" class="link">Source</a></p><div class="doc"><p>Split into lines, with line boundaries indicated by the given predicate. Satisfies <code>lines === linesBy (=='\n')</code>; equivalent to <code>split . dropFinalBlank . dropDelims . whenElt</code>. For example: </p><pre> linesBy (=='x') "dogxxxcatxbirdxx" == ["dog","","","cat","bird",""] </pre></div></div><h1 id="g:3">Other splitting methods </h1><div class="doc"><p>Other useful splitting methods which are not implemented using the combinator framework. </p></div><div class="top"><p class="src"><a name="v:splitEvery" class="def">splitEvery</a> :: <a href="/usr/share/doc/ghc/html/libraries/base-4.3.1.0/Data-Int.html#t:Int">Int</a> -> [e] -> [[e]]<a href="src/Data-List-Split-Internals.html#splitEvery" class="link">Source</a></p><div class="doc"><p><code><code><a href="Data-List-Split.html#v:splitEvery">splitEvery</a></code> n</code> splits a list into length-n pieces. The last piece will be shorter if <code>n</code> does not evenly divide the length of the list. If <code>n <= 0</code>, <code><code><a href="Data-List-Split.html#v:splitEvery">splitEvery</a></code> n l</code> returns an infinite list of empty lists. </p><p>Note that <code><code><a href="Data-List-Split.html#v:splitEvery">splitEvery</a></code> n []</code> is <code>[]</code>, not <code>[[]]</code>. This is intentional, and is consistent with a recursive definition of <code><a href="Data-List-Split.html#v:splitEvery">splitEvery</a></code>; it satisfies the property that </p><pre>splitEvery n xs ++ splitEvery n ys == splitEvery n (xs ++ ys)</pre><p>whenever <code>n</code> evenly divides the length of <code>xs</code>. </p></div></div><div class="top"><p class="src"><a name="v:chunk" class="def">chunk</a> :: <a href="/usr/share/doc/ghc/html/libraries/base-4.3.1.0/Data-Int.html#t:Int">Int</a> -> [e] -> [[e]]<a href="src/Data-List-Split-Internals.html#chunk" class="link">Source</a></p><div class="doc"><p>A common synonym for <code><a href="Data-List-Split.html#v:splitEvery">splitEvery</a></code>. </p></div></div><div class="top"><p class="src"><a name="v:splitPlaces" class="def">splitPlaces</a> :: <a href="/usr/share/doc/ghc/html/libraries/base-4.3.1.0/Prelude.html#t:Integral">Integral</a> a => [a] -> [e] -> [[e]]<a href="src/Data-List-Split-Internals.html#splitPlaces" class="link">Source</a></p><div class="doc"><p>Split a list into chunks of the given lengths. For example: </p><pre> splitPlaces [2,3,4] [1..20] == [[1,2],[3,4,5],[6,7,8,9]] splitPlaces [4,9] [1..10] == [[1,2,3,4],[5,6,7,8,9,10]] </pre><p>The behavior of <code><code><a href="Data-List-Split.html#v:splitPlaces">splitPlaces</a></code> ls xs</code> when <code><code><a href="/usr/share/doc/ghc/html/libraries/base-4.3.1.0/Data-List.html#v:sum">sum</a></code> ls /= <code><a href="/usr/share/doc/ghc/html/libraries/base-4.3.1.0/Data-List.html#v:length">length</a></code> xs</code> can be inferred from the above examples and the fact that <code><a href="Data-List-Split.html#v:splitPlaces">splitPlaces</a></code> is total. </p></div></div><div class="top"><p class="src"><a name="v:chop" class="def">chop</a> :: ([a] -> (b, [a])) -> [a] -> [b]<a href="src/Data-List-Split-Internals.html#chop" class="link">Source</a></p><div class="doc"><p>A useful recursion pattern for processing a list to produce a new list, often used for "chopping" up the input list. Typically chop is called with some function that will consume an initial prefix of the list and produce a value and the rest of the list. </p><p>For example, many common Prelude functions can be implemented in terms of <code>chop</code>: </p><pre> group :: (Eq a) => [a] -> [[a]] group = chop (\ xs@(x:_) -> span (==x) xs) words :: String -> [String] words = filter (not . null) . chop (span (not . isSpace) . dropWhile isSpace) </pre></div></div><h1 id="g:4">Splitting combinators </h1><div class="doc"><p>The core of the library is the <code><a href="Data-List-Split.html#t:Splitter">Splitter</a></code> type, which represents a particular list-splitting strategy. All of the combinators revolve around constructing or transforming <code><a href="Data-List-Split.html#t:Splitter">Splitter</a></code> objects; once a suitable <code><a href="Data-List-Split.html#t:Splitter">Splitter</a></code> has been created, it can be run with the <code><a href="Data-List-Split.html#v:split">split</a></code> function. For example: </p><pre> > split (dropBlanks . condense $ whenElt (<0)) [1,2,4,-5,-6,4,9,-19,-30] [[1,2,4],[-5,-6],[4,9],[-19,-30]] </pre></div><div class="top"><p class="src"><span class="keyword">data</span> <a name="t:Splitter" class="def">Splitter</a> a <a href="src/Data-List-Split-Internals.html#Splitter" class="link">Source</a></p><div class="doc"><p>A splitting strategy. </p></div></div><div class="top"><p class="src"><a name="v:defaultSplitter" class="def">defaultSplitter</a> :: <a href="Data-List-Split.html#t:Splitter">Splitter</a> a<a href="src/Data-List-Split-Internals.html#defaultSplitter" class="link">Source</a></p><div class="doc"><p>The default splitting strategy: keep delimiters in the output as separate chunks, don't condense multiple consecutive delimiters into one, keep initial and final blank chunks. Default delimiter is the constantly false predicate. </p><p>Note that <code><a href="Data-List-Split.html#v:defaultSplitter">defaultSplitter</a></code> should normally not be used; use <code><a href="Data-List-Split.html#v:oneOf">oneOf</a></code>, <code><a href="Data-List-Split.html#v:onSublist">onSublist</a></code>, or <code><a href="Data-List-Split.html#v:whenElt">whenElt</a></code> instead, which are the same as the <code><a href="Data-List-Split.html#v:defaultSplitter">defaultSplitter</a></code> with just the delimiter overridden. </p><p>The <code><a href="Data-List-Split.html#v:defaultSplitter">defaultSplitter</a></code> strategy with any delimiter gives a maximally information-preserving splitting strategy, in the sense that (a) taking the <code><a href="/usr/share/doc/ghc/html/libraries/base-4.3.1.0/Data-List.html#v:concat">concat</a></code> of the output yields the original list, and (b) given only the output list, we can reconstruct a <code><a href="Data-List-Split.html#t:Splitter">Splitter</a></code> which would produce the same output list again given the original input list. This default strategy can be overridden to allow discarding various sorts of information. </p></div></div><div class="top"><p class="src"><a name="v:split" class="def">split</a> :: <a href="Data-List-Split.html#t:Splitter">Splitter</a> a -> [a] -> [[a]]<a href="src/Data-List-Split-Internals.html#split" class="link">Source</a></p><div class="doc"><p>Split a list according to the given splitting strategy. This is how to "run" a <code><a href="Data-List-Split.html#t:Splitter">Splitter</a></code> that has been built using the other combinators. </p></div></div><h2 id="g:5">Basic strategies </h2><div class="doc"><p>All these basic strategies have the same parameters as the <code><a href="Data-List-Split.html#v:defaultSplitter">defaultSplitter</a></code> except for the delimiter. </p></div><div class="top"><p class="src"><a name="v:oneOf" class="def">oneOf</a> :: <a href="/usr/share/doc/ghc/html/libraries/base-4.3.1.0/Data-Eq.html#t:Eq">Eq</a> a => [a] -> <a href="Data-List-Split.html#t:Splitter">Splitter</a> a<a href="src/Data-List-Split-Internals.html#oneOf" class="link">Source</a></p><div class="doc"><p>A splitting strategy that splits on any one of the given elements. For example: </p><pre> split (oneOf "xyz") "aazbxyzcxd" == ["aa","z","b","x","","y","","z","c","x","d"] </pre></div></div><div class="top"><p class="src"><a name="v:onSublist" class="def">onSublist</a> :: <a href="/usr/share/doc/ghc/html/libraries/base-4.3.1.0/Data-Eq.html#t:Eq">Eq</a> a => [a] -> <a href="Data-List-Split.html#t:Splitter">Splitter</a> a<a href="src/Data-List-Split-Internals.html#onSublist" class="link">Source</a></p><div class="doc"><p>A splitting strategy that splits on the given list, when it is encountered as an exact subsequence. For example: </p><pre> split (onSublist "xyz") "aazbxyzcxd" == ["aazb","xyz","cxd"] </pre><p>Note that splitting on the empty list is a special case, which splits just before every element of the list being split. For example: </p><pre> split (onSublist "") "abc" == ["","","a","","b","","c"] split (dropDelims . dropBlanks $ onSublist "") "abc" == ["a","b","c"] </pre><p>However, if you want to break a list into singleton elements like this, you are better off using <code><code><a href="Data-List-Split.html#v:splitEvery">splitEvery</a></code> 1</code>, or better yet, <code><code><a href="/usr/share/doc/ghc/html/libraries/base-4.3.1.0/Data-List.html#v:map">map</a></code> (:[])</code>. </p></div></div><div class="top"><p class="src"><a name="v:whenElt" class="def">whenElt</a> :: (a -> <a href="/usr/share/doc/ghc/html/libraries/base-4.3.1.0/Data-Bool.html#t:Bool">Bool</a>) -> <a href="Data-List-Split.html#t:Splitter">Splitter</a> a<a href="src/Data-List-Split-Internals.html#whenElt" class="link">Source</a></p><div class="doc"><p>A splitting strategy that splits on any elements that satisfy the given predicate. For example: </p><pre> split (whenElt (<0)) [2,4,-3,6,-9,1] == [[2,4],[-3],[6],[-9],[1]] </pre></div></div><h2 id="g:6">Strategy transformers </h2><div class="doc"><p>Functions for altering splitting strategy parameters. </p></div><div class="top"><p class="src"><a name="v:dropDelims" class="def">dropDelims</a> :: <a href="Data-List-Split.html#t:Splitter">Splitter</a> a -> <a href="Data-List-Split.html#t:Splitter">Splitter</a> a<a href="src/Data-List-Split-Internals.html#dropDelims" class="link">Source</a></p><div class="doc"><p>Drop delimiters from the output (the default is to keep them). For example, </p><pre> split (oneOf ":") "a:b:c" == ["a", ":", "b", ":", "c"] split (dropDelims $ oneOf ":") "a:b:c" == ["a", "b", "c"] </pre></div></div><div class="top"><p class="src"><a name="v:keepDelimsL" class="def">keepDelimsL</a> :: <a href="Data-List-Split.html#t:Splitter">Splitter</a> a -> <a href="Data-List-Split.html#t:Splitter">Splitter</a> a<a href="src/Data-List-Split-Internals.html#keepDelimsL" class="link">Source</a></p><div class="doc"><p>Keep delimiters in the output by prepending them to adjacent chunks. For example: </p><pre> split (keepDelimsL $ oneOf "xyz") "aazbxyzcxd" == ["aa","zb","x","y","zc","xd"] </pre></div></div><div class="top"><p class="src"><a name="v:keepDelimsR" class="def">keepDelimsR</a> :: <a href="Data-List-Split.html#t:Splitter">Splitter</a> a -> <a href="Data-List-Split.html#t:Splitter">Splitter</a> a<a href="src/Data-List-Split-Internals.html#keepDelimsR" class="link">Source</a></p><div class="doc"><p>Keep delimiters in the output by appending them to adjacent chunks. For example: </p><pre> split (keepDelimsR $ oneOf "xyz") "aazbxyzcxd" == ["aaz","bx","y","z","cx","d"] </pre></div></div><div class="top"><p class="src"><a name="v:condense" class="def">condense</a> :: <a href="Data-List-Split.html#t:Splitter">Splitter</a> a -> <a href="Data-List-Split.html#t:Splitter">Splitter</a> a<a href="src/Data-List-Split-Internals.html#condense" class="link">Source</a></p><div class="doc"><p>Condense multiple consecutive delimiters into one. For example: </p><pre> split (condense $ oneOf "xyz") "aazbxyzcxd" == ["aa","z","b","xyz","c","x","d"] split (dropDelims $ oneOf "xyz") "aazbxyzcxd" == ["aa","b","","","c","d"] split (condense . dropDelims $ oneOf "xyz") "aazbxyzcxd" == ["aa","b","c","d"] </pre></div></div><div class="top"><p class="src"><a name="v:dropInitBlank" class="def">dropInitBlank</a> :: <a href="Data-List-Split.html#t:Splitter">Splitter</a> a -> <a href="Data-List-Split.html#t:Splitter">Splitter</a> a<a href="src/Data-List-Split-Internals.html#dropInitBlank" class="link">Source</a></p><div class="doc"><p>Don't generate a blank chunk if there is a delimiter at the beginning. For example: </p><pre> split (oneOf ":") ":a:b" == ["",":","a",":","b"] split (dropInitBlank $ oneOf ":") ":a:b" == [":","a",":","b"] </pre></div></div><div class="top"><p class="src"><a name="v:dropFinalBlank" class="def">dropFinalBlank</a> :: <a href="Data-List-Split.html#t:Splitter">Splitter</a> a -> <a href="Data-List-Split.html#t:Splitter">Splitter</a> a<a href="src/Data-List-Split-Internals.html#dropFinalBlank" class="link">Source</a></p><div class="doc"><p>Don't generate a blank chunk if there is a delimiter at the end. For example: </p><pre> split (oneOf ":") "a:b:" == ["a",":","b",":",""] split (dropFinalBlank $ oneOf ":") "a:b:" == ["a",":","b",":"] </pre></div></div><h2 id="g:7">Derived combinators </h2><div class="doc"><p>Combinators which can be defined in terms of other combinators, but are provided for convenience. </p></div><div class="top"><p class="src"><a name="v:dropBlanks" class="def">dropBlanks</a> :: <a href="Data-List-Split.html#t:Splitter">Splitter</a> a -> <a href="Data-List-Split.html#t:Splitter">Splitter</a> a<a href="src/Data-List-Split-Internals.html#dropBlanks" class="link">Source</a></p><div class="doc"><p>Drop all blank chunks from the output. Equivalent to <code><code><a href="Data-List-Split.html#v:dropInitBlank">dropInitBlank</a></code> . <code><a href="Data-List-Split.html#v:dropFinalBlank">dropFinalBlank</a></code> . <code><a href="Data-List-Split.html#v:condense">condense</a></code></code>. For example: </p><pre> split (oneOf ":") "::b:::a" == ["",":","",":","b",":","",":","",":","a"] split (dropBlanks $ oneOf ":") "::b:::a" == ["::","b",":::","a"] </pre></div></div><div class="top"><p class="src"><a name="v:startsWith" class="def">startsWith</a> :: <a href="/usr/share/doc/ghc/html/libraries/base-4.3.1.0/Data-Eq.html#t:Eq">Eq</a> a => [a] -> <a href="Data-List-Split.html#t:Splitter">Splitter</a> a<a href="src/Data-List-Split-Internals.html#startsWith" class="link">Source</a></p><div class="doc"><p>Make a strategy that splits a list into chunks that all start with the given subsequence (except possibly the first). Equivalent to <code><code><a href="Data-List-Split.html#v:dropInitBlank">dropInitBlank</a></code> . <code><a href="Data-List-Split.html#v:keepDelimsL">keepDelimsL</a></code> . <code><a href="Data-List-Split.html#v:onSublist">onSublist</a></code></code>. For example: </p><pre> split (startsWith "app") "applyapplicativeapplaudapproachapple" == ["apply","applicative","applaud","approach","apple"] </pre></div></div><div class="top"><p class="src"><a name="v:startsWithOneOf" class="def">startsWithOneOf</a> :: <a href="/usr/share/doc/ghc/html/libraries/base-4.3.1.0/Data-Eq.html#t:Eq">Eq</a> a => [a] -> <a href="Data-List-Split.html#t:Splitter">Splitter</a> a<a href="src/Data-List-Split-Internals.html#startsWithOneOf" class="link">Source</a></p><div class="doc"><p>Make a strategy that splits a list into chunks that all start with one of the given elements (except possibly the first). Equivalent to <code><code><a href="Data-List-Split.html#v:dropInitBlank">dropInitBlank</a></code> . <code><a href="Data-List-Split.html#v:keepDelimsL">keepDelimsL</a></code> . <code><a href="Data-List-Split.html#v:oneOf">oneOf</a></code></code>. For example: </p><pre> split (startsWithOneOf ['A'..'Z']) "ACamelCaseIdentifier" == ["A","Camel","Case","Identifier"] </pre></div></div><div class="top"><p class="src"><a name="v:endsWith" class="def">endsWith</a> :: <a href="/usr/share/doc/ghc/html/libraries/base-4.3.1.0/Data-Eq.html#t:Eq">Eq</a> a => [a] -> <a href="Data-List-Split.html#t:Splitter">Splitter</a> a<a href="src/Data-List-Split-Internals.html#endsWith" class="link">Source</a></p><div class="doc"><p>Make a strategy that splits a list into chunks that all end with the given subsequence, except possibly the last. Equivalent to <code><code><a href="Data-List-Split.html#v:dropFinalBlank">dropFinalBlank</a></code> . <code><a href="Data-List-Split.html#v:keepDelimsR">keepDelimsR</a></code> . <code><a href="Data-List-Split.html#v:onSublist">onSublist</a></code></code>. For example: </p><pre> split (endsWith "ly") "happilyslowlygnarlylily" == ["happily","slowly","gnarly","lily"] </pre></div></div><div class="top"><p class="src"><a name="v:endsWithOneOf" class="def">endsWithOneOf</a> :: <a href="/usr/share/doc/ghc/html/libraries/base-4.3.1.0/Data-Eq.html#t:Eq">Eq</a> a => [a] -> <a href="Data-List-Split.html#t:Splitter">Splitter</a> a<a href="src/Data-List-Split-Internals.html#endsWithOneOf" class="link">Source</a></p><div class="doc"><p>Make a strategy that splits a list into chunks that all end with one of the given elements, except possibly the last. Equivalent to <code><code><a href="Data-List-Split.html#v:dropFinalBlank">dropFinalBlank</a></code> . <code><a href="Data-List-Split.html#v:keepDelimsR">keepDelimsR</a></code> . <code><a href="Data-List-Split.html#v:oneOf">oneOf</a></code></code>. For example: </p><pre> split (condense $ endsWithOneOf ".,?! ") "Hi, there! How are you?" == ["Hi, ","there! ","How ","are ","you?"] </pre></div></div></div></div><div id="footer"><p>Produced by <a href="http://www.haskell.org/haddock/">Haddock</a> version 2.9.2</p></div></body></html>