<!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.ByteString</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-ByteString.html");}; //]]> </script></head><body><div id="package-header"><ul class="links" id="page-menu"><li><a href="index.html">Contents</a></li><li><a href="doc-index.html">Index</a></li></ul><p class="caption">bytestring-0.9.2.1: Fast, packed, strict and lazy byte arrays with a list interface</p></div><div id="content"><div id="module-header"><table class="info"><tr><th>Portability</th><td>portable</td></tr><tr><th>Stability</th><td>experimental</td></tr><tr><th>Maintainer</th><td>dons@cse.unsw.edu.au</td></tr><tr><th>Safe Haskell</th><td>Trustworthy</td></tr></table><p class="caption">Data.ByteString</p></div><div id="table-of-contents"><p class="caption">Contents</p><ul><li><a href="#g:1">The <code>ByteString</code> type </a></li><li><a href="#g:2">Introducing and eliminating <code><a href="Data-ByteString.html#t:ByteString">ByteString</a></code>s </a></li><li><a href="#g:3">Basic interface </a></li><li><a href="#g:4">Transforming ByteStrings </a></li><li><a href="#g:5">Reducing <code><a href="Data-ByteString.html#t:ByteString">ByteString</a></code>s (folds) </a><ul><li><a href="#g:6">Special folds </a></li></ul></li><li><a href="#g:7">Building ByteStrings </a><ul><li><a href="#g:8">Scans </a></li><li><a href="#g:9">Accumulating maps </a></li><li><a href="#g:10">Generating and unfolding ByteStrings </a></li></ul></li><li><a href="#g:11">Substrings </a><ul><li><a href="#g:12">Breaking strings </a></li><li><a href="#g:13">Breaking into many substrings </a></li></ul></li><li><a href="#g:14">Predicates </a><ul><li><a href="#g:15">Search for arbitrary substrings </a></li></ul></li><li><a href="#g:16">Searching ByteStrings </a><ul><li><a href="#g:17">Searching by equality </a></li><li><a href="#g:18">Searching with a predicate </a></li></ul></li><li><a href="#g:19">Indexing ByteStrings </a></li><li><a href="#g:20">Zipping and unzipping ByteStrings </a></li><li><a href="#g:21">Ordered ByteStrings </a></li><li><a href="#g:22">Low level conversions </a><ul><li><a href="#g:23">Copying ByteStrings </a></li><li><a href="#g:24">Packing <code><a href="../base-4.5.1.0/Foreign-C-String.html#t:CString">CString</a></code>s and pointers </a></li><li><a href="#g:25">Using ByteStrings as <code><a href="../base-4.5.1.0/Foreign-C-String.html#t:CString">CString</a></code>s </a></li></ul></li><li><a href="#g:26">I/O with <code><a href="Data-ByteString.html#t:ByteString">ByteString</a></code>s </a><ul><li><a href="#g:27">Standard input and output </a></li><li><a href="#g:28">Files </a></li><li><a href="#g:29">I/O with Handles </a></li></ul></li></ul></div><div id="description"><p class="caption">Description</p><div class="doc"><p>A time and space-efficient implementation of byte vectors using packed Word8 arrays, suitable for high performance use, both in terms of large data quantities, or high speed requirements. Byte vectors are encoded as strict <code><a href="../base-4.5.1.0/Data-Word.html#t:Word8">Word8</a></code> arrays of bytes, held in a <code><a href="../base-4.5.1.0/Foreign-ForeignPtr-Safe.html#t:ForeignPtr">ForeignPtr</a></code>, and can be passed between C and Haskell with little effort. </p><p>This module is intended to be imported <code>qualified</code>, to avoid name clashes with <a href="../base-4.5.1.0/Prelude.html">Prelude</a> functions. eg. </p><pre> import qualified Data.ByteString as B </pre><p>Original GHC implementation by Bryan O'Sullivan. Rewritten to use <code><a href="Data-Array-Unboxed.html#t:UArray">UArray</a></code> by Simon Marlow. Rewritten to support slices and use <code><a href="../base-4.5.1.0/Foreign-ForeignPtr-Safe.html#t:ForeignPtr">ForeignPtr</a></code> by David Roundy. Polished and extended by Don Stewart. </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"><span class="keyword">data</span> <a href="#t:ByteString">ByteString</a> </li><li class="src short"><a href="#v:empty">empty</a> :: <a href="Data-ByteString.html#t:ByteString">ByteString</a></li><li class="src short"><a href="#v:singleton">singleton</a> :: <a href="../base-4.5.1.0/Data-Word.html#t:Word8">Word8</a> -> <a href="Data-ByteString.html#t:ByteString">ByteString</a></li><li class="src short"><a href="#v:pack">pack</a> :: [<a href="../base-4.5.1.0/Data-Word.html#t:Word8">Word8</a>] -> <a href="Data-ByteString.html#t:ByteString">ByteString</a></li><li class="src short"><a href="#v:unpack">unpack</a> :: <a href="Data-ByteString.html#t:ByteString">ByteString</a> -> [<a href="../base-4.5.1.0/Data-Word.html#t:Word8">Word8</a>]</li><li class="src short"><a href="#v:cons">cons</a> :: <a href="../base-4.5.1.0/Data-Word.html#t:Word8">Word8</a> -> <a href="Data-ByteString.html#t:ByteString">ByteString</a> -> <a href="Data-ByteString.html#t:ByteString">ByteString</a></li><li class="src short"><a href="#v:snoc">snoc</a> :: <a href="Data-ByteString.html#t:ByteString">ByteString</a> -> <a href="../base-4.5.1.0/Data-Word.html#t:Word8">Word8</a> -> <a href="Data-ByteString.html#t:ByteString">ByteString</a></li><li class="src short"><a href="#v:append">append</a> :: <a href="Data-ByteString.html#t:ByteString">ByteString</a> -> <a href="Data-ByteString.html#t:ByteString">ByteString</a> -> <a href="Data-ByteString.html#t:ByteString">ByteString</a></li><li class="src short"><a href="#v:head">head</a> :: <a href="Data-ByteString.html#t:ByteString">ByteString</a> -> <a href="../base-4.5.1.0/Data-Word.html#t:Word8">Word8</a></li><li class="src short"><a href="#v:uncons">uncons</a> :: <a href="Data-ByteString.html#t:ByteString">ByteString</a> -> <a href="../base-4.5.1.0/Data-Maybe.html#t:Maybe">Maybe</a> (<a href="../base-4.5.1.0/Data-Word.html#t:Word8">Word8</a>, <a href="Data-ByteString.html#t:ByteString">ByteString</a>)</li><li class="src short"><a href="#v:last">last</a> :: <a href="Data-ByteString.html#t:ByteString">ByteString</a> -> <a href="../base-4.5.1.0/Data-Word.html#t:Word8">Word8</a></li><li class="src short"><a href="#v:tail">tail</a> :: <a href="Data-ByteString.html#t:ByteString">ByteString</a> -> <a href="Data-ByteString.html#t:ByteString">ByteString</a></li><li class="src short"><a href="#v:init">init</a> :: <a href="Data-ByteString.html#t:ByteString">ByteString</a> -> <a href="Data-ByteString.html#t:ByteString">ByteString</a></li><li class="src short"><a href="#v:null">null</a> :: <a href="Data-ByteString.html#t:ByteString">ByteString</a> -> <a href="../base-4.5.1.0/Data-Bool.html#t:Bool">Bool</a></li><li class="src short"><a href="#v:length">length</a> :: <a href="Data-ByteString.html#t:ByteString">ByteString</a> -> <a href="../base-4.5.1.0/Data-Int.html#t:Int">Int</a></li><li class="src short"><a href="#v:map">map</a> :: (<a href="../base-4.5.1.0/Data-Word.html#t:Word8">Word8</a> -> <a href="../base-4.5.1.0/Data-Word.html#t:Word8">Word8</a>) -> <a href="Data-ByteString.html#t:ByteString">ByteString</a> -> <a href="Data-ByteString.html#t:ByteString">ByteString</a></li><li class="src short"><a href="#v:reverse">reverse</a> :: <a href="Data-ByteString.html#t:ByteString">ByteString</a> -> <a href="Data-ByteString.html#t:ByteString">ByteString</a></li><li class="src short"><a href="#v:intersperse">intersperse</a> :: <a href="../base-4.5.1.0/Data-Word.html#t:Word8">Word8</a> -> <a href="Data-ByteString.html#t:ByteString">ByteString</a> -> <a href="Data-ByteString.html#t:ByteString">ByteString</a></li><li class="src short"><a href="#v:intercalate">intercalate</a> :: <a href="Data-ByteString.html#t:ByteString">ByteString</a> -> [<a href="Data-ByteString.html#t:ByteString">ByteString</a>] -> <a href="Data-ByteString.html#t:ByteString">ByteString</a></li><li class="src short"><a href="#v:transpose">transpose</a> :: [<a href="Data-ByteString.html#t:ByteString">ByteString</a>] -> [<a href="Data-ByteString.html#t:ByteString">ByteString</a>]</li><li class="src short"><a href="#v:foldl">foldl</a> :: (a -> <a href="../base-4.5.1.0/Data-Word.html#t:Word8">Word8</a> -> a) -> a -> <a href="Data-ByteString.html#t:ByteString">ByteString</a> -> a</li><li class="src short"><a href="#v:foldl-39-">foldl'</a> :: (a -> <a href="../base-4.5.1.0/Data-Word.html#t:Word8">Word8</a> -> a) -> a -> <a href="Data-ByteString.html#t:ByteString">ByteString</a> -> a</li><li class="src short"><a href="#v:foldl1">foldl1</a> :: (<a href="../base-4.5.1.0/Data-Word.html#t:Word8">Word8</a> -> <a href="../base-4.5.1.0/Data-Word.html#t:Word8">Word8</a> -> <a href="../base-4.5.1.0/Data-Word.html#t:Word8">Word8</a>) -> <a href="Data-ByteString.html#t:ByteString">ByteString</a> -> <a href="../base-4.5.1.0/Data-Word.html#t:Word8">Word8</a></li><li class="src short"><a href="#v:foldl1-39-">foldl1'</a> :: (<a href="../base-4.5.1.0/Data-Word.html#t:Word8">Word8</a> -> <a href="../base-4.5.1.0/Data-Word.html#t:Word8">Word8</a> -> <a href="../base-4.5.1.0/Data-Word.html#t:Word8">Word8</a>) -> <a href="Data-ByteString.html#t:ByteString">ByteString</a> -> <a href="../base-4.5.1.0/Data-Word.html#t:Word8">Word8</a></li><li class="src short"><a href="#v:foldr">foldr</a> :: (<a href="../base-4.5.1.0/Data-Word.html#t:Word8">Word8</a> -> a -> a) -> a -> <a href="Data-ByteString.html#t:ByteString">ByteString</a> -> a</li><li class="src short"><a href="#v:foldr-39-">foldr'</a> :: (<a href="../base-4.5.1.0/Data-Word.html#t:Word8">Word8</a> -> a -> a) -> a -> <a href="Data-ByteString.html#t:ByteString">ByteString</a> -> a</li><li class="src short"><a href="#v:foldr1">foldr1</a> :: (<a href="../base-4.5.1.0/Data-Word.html#t:Word8">Word8</a> -> <a href="../base-4.5.1.0/Data-Word.html#t:Word8">Word8</a> -> <a href="../base-4.5.1.0/Data-Word.html#t:Word8">Word8</a>) -> <a href="Data-ByteString.html#t:ByteString">ByteString</a> -> <a href="../base-4.5.1.0/Data-Word.html#t:Word8">Word8</a></li><li class="src short"><a href="#v:foldr1-39-">foldr1'</a> :: (<a href="../base-4.5.1.0/Data-Word.html#t:Word8">Word8</a> -> <a href="../base-4.5.1.0/Data-Word.html#t:Word8">Word8</a> -> <a href="../base-4.5.1.0/Data-Word.html#t:Word8">Word8</a>) -> <a href="Data-ByteString.html#t:ByteString">ByteString</a> -> <a href="../base-4.5.1.0/Data-Word.html#t:Word8">Word8</a></li><li class="src short"><a href="#v:concat">concat</a> :: [<a href="Data-ByteString.html#t:ByteString">ByteString</a>] -> <a href="Data-ByteString.html#t:ByteString">ByteString</a></li><li class="src short"><a href="#v:concatMap">concatMap</a> :: (<a href="../base-4.5.1.0/Data-Word.html#t:Word8">Word8</a> -> <a href="Data-ByteString.html#t:ByteString">ByteString</a>) -> <a href="Data-ByteString.html#t:ByteString">ByteString</a> -> <a href="Data-ByteString.html#t:ByteString">ByteString</a></li><li class="src short"><a href="#v:any">any</a> :: (<a href="../base-4.5.1.0/Data-Word.html#t:Word8">Word8</a> -> <a href="../base-4.5.1.0/Data-Bool.html#t:Bool">Bool</a>) -> <a href="Data-ByteString.html#t:ByteString">ByteString</a> -> <a href="../base-4.5.1.0/Data-Bool.html#t:Bool">Bool</a></li><li class="src short"><a href="#v:all">all</a> :: (<a href="../base-4.5.1.0/Data-Word.html#t:Word8">Word8</a> -> <a href="../base-4.5.1.0/Data-Bool.html#t:Bool">Bool</a>) -> <a href="Data-ByteString.html#t:ByteString">ByteString</a> -> <a href="../base-4.5.1.0/Data-Bool.html#t:Bool">Bool</a></li><li class="src short"><a href="#v:maximum">maximum</a> :: <a href="Data-ByteString.html#t:ByteString">ByteString</a> -> <a href="../base-4.5.1.0/Data-Word.html#t:Word8">Word8</a></li><li class="src short"><a href="#v:minimum">minimum</a> :: <a href="Data-ByteString.html#t:ByteString">ByteString</a> -> <a href="../base-4.5.1.0/Data-Word.html#t:Word8">Word8</a></li><li class="src short"><a href="#v:scanl">scanl</a> :: (<a href="../base-4.5.1.0/Data-Word.html#t:Word8">Word8</a> -> <a href="../base-4.5.1.0/Data-Word.html#t:Word8">Word8</a> -> <a href="../base-4.5.1.0/Data-Word.html#t:Word8">Word8</a>) -> <a href="../base-4.5.1.0/Data-Word.html#t:Word8">Word8</a> -> <a href="Data-ByteString.html#t:ByteString">ByteString</a> -> <a href="Data-ByteString.html#t:ByteString">ByteString</a></li><li class="src short"><a href="#v:scanl1">scanl1</a> :: (<a href="../base-4.5.1.0/Data-Word.html#t:Word8">Word8</a> -> <a href="../base-4.5.1.0/Data-Word.html#t:Word8">Word8</a> -> <a href="../base-4.5.1.0/Data-Word.html#t:Word8">Word8</a>) -> <a href="Data-ByteString.html#t:ByteString">ByteString</a> -> <a href="Data-ByteString.html#t:ByteString">ByteString</a></li><li class="src short"><a href="#v:scanr">scanr</a> :: (<a href="../base-4.5.1.0/Data-Word.html#t:Word8">Word8</a> -> <a href="../base-4.5.1.0/Data-Word.html#t:Word8">Word8</a> -> <a href="../base-4.5.1.0/Data-Word.html#t:Word8">Word8</a>) -> <a href="../base-4.5.1.0/Data-Word.html#t:Word8">Word8</a> -> <a href="Data-ByteString.html#t:ByteString">ByteString</a> -> <a href="Data-ByteString.html#t:ByteString">ByteString</a></li><li class="src short"><a href="#v:scanr1">scanr1</a> :: (<a href="../base-4.5.1.0/Data-Word.html#t:Word8">Word8</a> -> <a href="../base-4.5.1.0/Data-Word.html#t:Word8">Word8</a> -> <a href="../base-4.5.1.0/Data-Word.html#t:Word8">Word8</a>) -> <a href="Data-ByteString.html#t:ByteString">ByteString</a> -> <a href="Data-ByteString.html#t:ByteString">ByteString</a></li><li class="src short"><a href="#v:mapAccumL">mapAccumL</a> :: (acc -> <a href="../base-4.5.1.0/Data-Word.html#t:Word8">Word8</a> -> (acc, <a href="../base-4.5.1.0/Data-Word.html#t:Word8">Word8</a>)) -> acc -> <a href="Data-ByteString.html#t:ByteString">ByteString</a> -> (acc, <a href="Data-ByteString.html#t:ByteString">ByteString</a>)</li><li class="src short"><a href="#v:mapAccumR">mapAccumR</a> :: (acc -> <a href="../base-4.5.1.0/Data-Word.html#t:Word8">Word8</a> -> (acc, <a href="../base-4.5.1.0/Data-Word.html#t:Word8">Word8</a>)) -> acc -> <a href="Data-ByteString.html#t:ByteString">ByteString</a> -> (acc, <a href="Data-ByteString.html#t:ByteString">ByteString</a>)</li><li class="src short"><a href="#v:replicate">replicate</a> :: <a href="../base-4.5.1.0/Data-Int.html#t:Int">Int</a> -> <a href="../base-4.5.1.0/Data-Word.html#t:Word8">Word8</a> -> <a href="Data-ByteString.html#t:ByteString">ByteString</a></li><li class="src short"><a href="#v:unfoldr">unfoldr</a> :: (a -> <a href="../base-4.5.1.0/Data-Maybe.html#t:Maybe">Maybe</a> (<a href="../base-4.5.1.0/Data-Word.html#t:Word8">Word8</a>, a)) -> a -> <a href="Data-ByteString.html#t:ByteString">ByteString</a></li><li class="src short"><a href="#v:unfoldrN">unfoldrN</a> :: <a href="../base-4.5.1.0/Data-Int.html#t:Int">Int</a> -> (a -> <a href="../base-4.5.1.0/Data-Maybe.html#t:Maybe">Maybe</a> (<a href="../base-4.5.1.0/Data-Word.html#t:Word8">Word8</a>, a)) -> a -> (<a href="Data-ByteString.html#t:ByteString">ByteString</a>, <a href="../base-4.5.1.0/Data-Maybe.html#t:Maybe">Maybe</a> a)</li><li class="src short"><a href="#v:take">take</a> :: <a href="../base-4.5.1.0/Data-Int.html#t:Int">Int</a> -> <a href="Data-ByteString.html#t:ByteString">ByteString</a> -> <a href="Data-ByteString.html#t:ByteString">ByteString</a></li><li class="src short"><a href="#v:drop">drop</a> :: <a href="../base-4.5.1.0/Data-Int.html#t:Int">Int</a> -> <a href="Data-ByteString.html#t:ByteString">ByteString</a> -> <a href="Data-ByteString.html#t:ByteString">ByteString</a></li><li class="src short"><a href="#v:splitAt">splitAt</a> :: <a href="../base-4.5.1.0/Data-Int.html#t:Int">Int</a> -> <a href="Data-ByteString.html#t:ByteString">ByteString</a> -> (<a href="Data-ByteString.html#t:ByteString">ByteString</a>, <a href="Data-ByteString.html#t:ByteString">ByteString</a>)</li><li class="src short"><a href="#v:takeWhile">takeWhile</a> :: (<a href="../base-4.5.1.0/Data-Word.html#t:Word8">Word8</a> -> <a href="../base-4.5.1.0/Data-Bool.html#t:Bool">Bool</a>) -> <a href="Data-ByteString.html#t:ByteString">ByteString</a> -> <a href="Data-ByteString.html#t:ByteString">ByteString</a></li><li class="src short"><a href="#v:dropWhile">dropWhile</a> :: (<a href="../base-4.5.1.0/Data-Word.html#t:Word8">Word8</a> -> <a href="../base-4.5.1.0/Data-Bool.html#t:Bool">Bool</a>) -> <a href="Data-ByteString.html#t:ByteString">ByteString</a> -> <a href="Data-ByteString.html#t:ByteString">ByteString</a></li><li class="src short"><a href="#v:span">span</a> :: (<a href="../base-4.5.1.0/Data-Word.html#t:Word8">Word8</a> -> <a href="../base-4.5.1.0/Data-Bool.html#t:Bool">Bool</a>) -> <a href="Data-ByteString.html#t:ByteString">ByteString</a> -> (<a href="Data-ByteString.html#t:ByteString">ByteString</a>, <a href="Data-ByteString.html#t:ByteString">ByteString</a>)</li><li class="src short"><a href="#v:spanEnd">spanEnd</a> :: (<a href="../base-4.5.1.0/Data-Word.html#t:Word8">Word8</a> -> <a href="../base-4.5.1.0/Data-Bool.html#t:Bool">Bool</a>) -> <a href="Data-ByteString.html#t:ByteString">ByteString</a> -> (<a href="Data-ByteString.html#t:ByteString">ByteString</a>, <a href="Data-ByteString.html#t:ByteString">ByteString</a>)</li><li class="src short"><a href="#v:break">break</a> :: (<a href="../base-4.5.1.0/Data-Word.html#t:Word8">Word8</a> -> <a href="../base-4.5.1.0/Data-Bool.html#t:Bool">Bool</a>) -> <a href="Data-ByteString.html#t:ByteString">ByteString</a> -> (<a href="Data-ByteString.html#t:ByteString">ByteString</a>, <a href="Data-ByteString.html#t:ByteString">ByteString</a>)</li><li class="src short"><a href="#v:breakEnd">breakEnd</a> :: (<a href="../base-4.5.1.0/Data-Word.html#t:Word8">Word8</a> -> <a href="../base-4.5.1.0/Data-Bool.html#t:Bool">Bool</a>) -> <a href="Data-ByteString.html#t:ByteString">ByteString</a> -> (<a href="Data-ByteString.html#t:ByteString">ByteString</a>, <a href="Data-ByteString.html#t:ByteString">ByteString</a>)</li><li class="src short"><a href="#v:group">group</a> :: <a href="Data-ByteString.html#t:ByteString">ByteString</a> -> [<a href="Data-ByteString.html#t:ByteString">ByteString</a>]</li><li class="src short"><a href="#v:groupBy">groupBy</a> :: (<a href="../base-4.5.1.0/Data-Word.html#t:Word8">Word8</a> -> <a href="../base-4.5.1.0/Data-Word.html#t:Word8">Word8</a> -> <a href="../base-4.5.1.0/Data-Bool.html#t:Bool">Bool</a>) -> <a href="Data-ByteString.html#t:ByteString">ByteString</a> -> [<a href="Data-ByteString.html#t:ByteString">ByteString</a>]</li><li class="src short"><a href="#v:inits">inits</a> :: <a href="Data-ByteString.html#t:ByteString">ByteString</a> -> [<a href="Data-ByteString.html#t:ByteString">ByteString</a>]</li><li class="src short"><a href="#v:tails">tails</a> :: <a href="Data-ByteString.html#t:ByteString">ByteString</a> -> [<a href="Data-ByteString.html#t:ByteString">ByteString</a>]</li><li class="src short"><a href="#v:split">split</a> :: <a href="../base-4.5.1.0/Data-Word.html#t:Word8">Word8</a> -> <a href="Data-ByteString.html#t:ByteString">ByteString</a> -> [<a href="Data-ByteString.html#t:ByteString">ByteString</a>]</li><li class="src short"><a href="#v:splitWith">splitWith</a> :: (<a href="../base-4.5.1.0/Data-Word.html#t:Word8">Word8</a> -> <a href="../base-4.5.1.0/Data-Bool.html#t:Bool">Bool</a>) -> <a href="Data-ByteString.html#t:ByteString">ByteString</a> -> [<a href="Data-ByteString.html#t:ByteString">ByteString</a>]</li><li class="src short"><a href="#v:isPrefixOf">isPrefixOf</a> :: <a href="Data-ByteString.html#t:ByteString">ByteString</a> -> <a href="Data-ByteString.html#t:ByteString">ByteString</a> -> <a href="../base-4.5.1.0/Data-Bool.html#t:Bool">Bool</a></li><li class="src short"><a href="#v:isSuffixOf">isSuffixOf</a> :: <a href="Data-ByteString.html#t:ByteString">ByteString</a> -> <a href="Data-ByteString.html#t:ByteString">ByteString</a> -> <a href="../base-4.5.1.0/Data-Bool.html#t:Bool">Bool</a></li><li class="src short"><a href="#v:isInfixOf">isInfixOf</a> :: <a href="Data-ByteString.html#t:ByteString">ByteString</a> -> <a href="Data-ByteString.html#t:ByteString">ByteString</a> -> <a href="../base-4.5.1.0/Data-Bool.html#t:Bool">Bool</a></li><li class="src short"><a href="#v:breakSubstring">breakSubstring</a> :: <a href="Data-ByteString.html#t:ByteString">ByteString</a> -> <a href="Data-ByteString.html#t:ByteString">ByteString</a> -> (<a href="Data-ByteString.html#t:ByteString">ByteString</a>, <a href="Data-ByteString.html#t:ByteString">ByteString</a>)</li><li class="src short"><a href="#v:findSubstring">findSubstring</a> :: <a href="Data-ByteString.html#t:ByteString">ByteString</a> -> <a href="Data-ByteString.html#t:ByteString">ByteString</a> -> <a href="../base-4.5.1.0/Data-Maybe.html#t:Maybe">Maybe</a> <a href="../base-4.5.1.0/Data-Int.html#t:Int">Int</a></li><li class="src short"><a href="#v:findSubstrings">findSubstrings</a> :: <a href="Data-ByteString.html#t:ByteString">ByteString</a> -> <a href="Data-ByteString.html#t:ByteString">ByteString</a> -> [<a href="../base-4.5.1.0/Data-Int.html#t:Int">Int</a>]</li><li class="src short"><a href="#v:elem">elem</a> :: <a href="../base-4.5.1.0/Data-Word.html#t:Word8">Word8</a> -> <a href="Data-ByteString.html#t:ByteString">ByteString</a> -> <a href="../base-4.5.1.0/Data-Bool.html#t:Bool">Bool</a></li><li class="src short"><a href="#v:notElem">notElem</a> :: <a href="../base-4.5.1.0/Data-Word.html#t:Word8">Word8</a> -> <a href="Data-ByteString.html#t:ByteString">ByteString</a> -> <a href="../base-4.5.1.0/Data-Bool.html#t:Bool">Bool</a></li><li class="src short"><a href="#v:find">find</a> :: (<a href="../base-4.5.1.0/Data-Word.html#t:Word8">Word8</a> -> <a href="../base-4.5.1.0/Data-Bool.html#t:Bool">Bool</a>) -> <a href="Data-ByteString.html#t:ByteString">ByteString</a> -> <a href="../base-4.5.1.0/Data-Maybe.html#t:Maybe">Maybe</a> <a href="../base-4.5.1.0/Data-Word.html#t:Word8">Word8</a></li><li class="src short"><a href="#v:filter">filter</a> :: (<a href="../base-4.5.1.0/Data-Word.html#t:Word8">Word8</a> -> <a href="../base-4.5.1.0/Data-Bool.html#t:Bool">Bool</a>) -> <a href="Data-ByteString.html#t:ByteString">ByteString</a> -> <a href="Data-ByteString.html#t:ByteString">ByteString</a></li><li class="src short"><a href="#v:partition">partition</a> :: (<a href="../base-4.5.1.0/Data-Word.html#t:Word8">Word8</a> -> <a href="../base-4.5.1.0/Data-Bool.html#t:Bool">Bool</a>) -> <a href="Data-ByteString.html#t:ByteString">ByteString</a> -> (<a href="Data-ByteString.html#t:ByteString">ByteString</a>, <a href="Data-ByteString.html#t:ByteString">ByteString</a>)</li><li class="src short"><a href="#v:index">index</a> :: <a href="Data-ByteString.html#t:ByteString">ByteString</a> -> <a href="../base-4.5.1.0/Data-Int.html#t:Int">Int</a> -> <a href="../base-4.5.1.0/Data-Word.html#t:Word8">Word8</a></li><li class="src short"><a href="#v:elemIndex">elemIndex</a> :: <a href="../base-4.5.1.0/Data-Word.html#t:Word8">Word8</a> -> <a href="Data-ByteString.html#t:ByteString">ByteString</a> -> <a href="../base-4.5.1.0/Data-Maybe.html#t:Maybe">Maybe</a> <a href="../base-4.5.1.0/Data-Int.html#t:Int">Int</a></li><li class="src short"><a href="#v:elemIndices">elemIndices</a> :: <a href="../base-4.5.1.0/Data-Word.html#t:Word8">Word8</a> -> <a href="Data-ByteString.html#t:ByteString">ByteString</a> -> [<a href="../base-4.5.1.0/Data-Int.html#t:Int">Int</a>]</li><li class="src short"><a href="#v:elemIndexEnd">elemIndexEnd</a> :: <a href="../base-4.5.1.0/Data-Word.html#t:Word8">Word8</a> -> <a href="Data-ByteString.html#t:ByteString">ByteString</a> -> <a href="../base-4.5.1.0/Data-Maybe.html#t:Maybe">Maybe</a> <a href="../base-4.5.1.0/Data-Int.html#t:Int">Int</a></li><li class="src short"><a href="#v:findIndex">findIndex</a> :: (<a href="../base-4.5.1.0/Data-Word.html#t:Word8">Word8</a> -> <a href="../base-4.5.1.0/Data-Bool.html#t:Bool">Bool</a>) -> <a href="Data-ByteString.html#t:ByteString">ByteString</a> -> <a href="../base-4.5.1.0/Data-Maybe.html#t:Maybe">Maybe</a> <a href="../base-4.5.1.0/Data-Int.html#t:Int">Int</a></li><li class="src short"><a href="#v:findIndices">findIndices</a> :: (<a href="../base-4.5.1.0/Data-Word.html#t:Word8">Word8</a> -> <a href="../base-4.5.1.0/Data-Bool.html#t:Bool">Bool</a>) -> <a href="Data-ByteString.html#t:ByteString">ByteString</a> -> [<a href="../base-4.5.1.0/Data-Int.html#t:Int">Int</a>]</li><li class="src short"><a href="#v:count">count</a> :: <a href="../base-4.5.1.0/Data-Word.html#t:Word8">Word8</a> -> <a href="Data-ByteString.html#t:ByteString">ByteString</a> -> <a href="../base-4.5.1.0/Data-Int.html#t:Int">Int</a></li><li class="src short"><a href="#v:zip">zip</a> :: <a href="Data-ByteString.html#t:ByteString">ByteString</a> -> <a href="Data-ByteString.html#t:ByteString">ByteString</a> -> [(<a href="../base-4.5.1.0/Data-Word.html#t:Word8">Word8</a>, <a href="../base-4.5.1.0/Data-Word.html#t:Word8">Word8</a>)]</li><li class="src short"><a href="#v:zipWith">zipWith</a> :: (<a href="../base-4.5.1.0/Data-Word.html#t:Word8">Word8</a> -> <a href="../base-4.5.1.0/Data-Word.html#t:Word8">Word8</a> -> a) -> <a href="Data-ByteString.html#t:ByteString">ByteString</a> -> <a href="Data-ByteString.html#t:ByteString">ByteString</a> -> [a]</li><li class="src short"><a href="#v:unzip">unzip</a> :: [(<a href="../base-4.5.1.0/Data-Word.html#t:Word8">Word8</a>, <a href="../base-4.5.1.0/Data-Word.html#t:Word8">Word8</a>)] -> (<a href="Data-ByteString.html#t:ByteString">ByteString</a>, <a href="Data-ByteString.html#t:ByteString">ByteString</a>)</li><li class="src short"><a href="#v:sort">sort</a> :: <a href="Data-ByteString.html#t:ByteString">ByteString</a> -> <a href="Data-ByteString.html#t:ByteString">ByteString</a></li><li class="src short"><a href="#v:copy">copy</a> :: <a href="Data-ByteString.html#t:ByteString">ByteString</a> -> <a href="Data-ByteString.html#t:ByteString">ByteString</a></li><li class="src short"><a href="#v:packCString">packCString</a> :: <a href="../base-4.5.1.0/Foreign-C-String.html#t:CString">CString</a> -> <a href="../base-4.5.1.0/System-IO.html#t:IO">IO</a> <a href="Data-ByteString.html#t:ByteString">ByteString</a></li><li class="src short"><a href="#v:packCStringLen">packCStringLen</a> :: <a href="../base-4.5.1.0/Foreign-C-String.html#t:CStringLen">CStringLen</a> -> <a href="../base-4.5.1.0/System-IO.html#t:IO">IO</a> <a href="Data-ByteString.html#t:ByteString">ByteString</a></li><li class="src short"><a href="#v:useAsCString">useAsCString</a> :: <a href="Data-ByteString.html#t:ByteString">ByteString</a> -> (<a href="../base-4.5.1.0/Foreign-C-String.html#t:CString">CString</a> -> <a href="../base-4.5.1.0/System-IO.html#t:IO">IO</a> a) -> <a href="../base-4.5.1.0/System-IO.html#t:IO">IO</a> a</li><li class="src short"><a href="#v:useAsCStringLen">useAsCStringLen</a> :: <a href="Data-ByteString.html#t:ByteString">ByteString</a> -> (<a href="../base-4.5.1.0/Foreign-C-String.html#t:CStringLen">CStringLen</a> -> <a href="../base-4.5.1.0/System-IO.html#t:IO">IO</a> a) -> <a href="../base-4.5.1.0/System-IO.html#t:IO">IO</a> a</li><li class="src short"><a href="#v:getLine">getLine</a> :: <a href="../base-4.5.1.0/System-IO.html#t:IO">IO</a> <a href="Data-ByteString.html#t:ByteString">ByteString</a></li><li class="src short"><a href="#v:getContents">getContents</a> :: <a href="../base-4.5.1.0/System-IO.html#t:IO">IO</a> <a href="Data-ByteString.html#t:ByteString">ByteString</a></li><li class="src short"><a href="#v:putStr">putStr</a> :: <a href="Data-ByteString.html#t:ByteString">ByteString</a> -> <a href="../base-4.5.1.0/System-IO.html#t:IO">IO</a> <a href="../ghc-prim-0.2.0.0/GHC-Tuple.html#t:-40--41-">()</a></li><li class="src short"><a href="#v:putStrLn">putStrLn</a> :: <a href="Data-ByteString.html#t:ByteString">ByteString</a> -> <a href="../base-4.5.1.0/System-IO.html#t:IO">IO</a> <a href="../ghc-prim-0.2.0.0/GHC-Tuple.html#t:-40--41-">()</a></li><li class="src short"><a href="#v:interact">interact</a> :: (<a href="Data-ByteString.html#t:ByteString">ByteString</a> -> <a href="Data-ByteString.html#t:ByteString">ByteString</a>) -> <a href="../base-4.5.1.0/System-IO.html#t:IO">IO</a> <a href="../ghc-prim-0.2.0.0/GHC-Tuple.html#t:-40--41-">()</a></li><li class="src short"><a href="#v:readFile">readFile</a> :: <a href="../base-4.5.1.0/System-IO.html#t:FilePath">FilePath</a> -> <a href="../base-4.5.1.0/System-IO.html#t:IO">IO</a> <a href="Data-ByteString.html#t:ByteString">ByteString</a></li><li class="src short"><a href="#v:writeFile">writeFile</a> :: <a href="../base-4.5.1.0/System-IO.html#t:FilePath">FilePath</a> -> <a href="Data-ByteString.html#t:ByteString">ByteString</a> -> <a href="../base-4.5.1.0/System-IO.html#t:IO">IO</a> <a href="../ghc-prim-0.2.0.0/GHC-Tuple.html#t:-40--41-">()</a></li><li class="src short"><a href="#v:appendFile">appendFile</a> :: <a href="../base-4.5.1.0/System-IO.html#t:FilePath">FilePath</a> -> <a href="Data-ByteString.html#t:ByteString">ByteString</a> -> <a href="../base-4.5.1.0/System-IO.html#t:IO">IO</a> <a href="../ghc-prim-0.2.0.0/GHC-Tuple.html#t:-40--41-">()</a></li><li class="src short"><a href="#v:hGetLine">hGetLine</a> :: <a href="../base-4.5.1.0/GHC-IO-Handle.html#t:Handle">Handle</a> -> <a href="../base-4.5.1.0/System-IO.html#t:IO">IO</a> <a href="Data-ByteString.html#t:ByteString">ByteString</a></li><li class="src short"><a href="#v:hGetContents">hGetContents</a> :: <a href="../base-4.5.1.0/GHC-IO-Handle.html#t:Handle">Handle</a> -> <a href="../base-4.5.1.0/System-IO.html#t:IO">IO</a> <a href="Data-ByteString.html#t:ByteString">ByteString</a></li><li class="src short"><a href="#v:hGet">hGet</a> :: <a href="../base-4.5.1.0/GHC-IO-Handle.html#t:Handle">Handle</a> -> <a href="../base-4.5.1.0/Data-Int.html#t:Int">Int</a> -> <a href="../base-4.5.1.0/System-IO.html#t:IO">IO</a> <a href="Data-ByteString.html#t:ByteString">ByteString</a></li><li class="src short"><a href="#v:hGetSome">hGetSome</a> :: <a href="../base-4.5.1.0/GHC-IO-Handle.html#t:Handle">Handle</a> -> <a href="../base-4.5.1.0/Data-Int.html#t:Int">Int</a> -> <a href="../base-4.5.1.0/System-IO.html#t:IO">IO</a> <a href="Data-ByteString.html#t:ByteString">ByteString</a></li><li class="src short"><a href="#v:hGetNonBlocking">hGetNonBlocking</a> :: <a href="../base-4.5.1.0/GHC-IO-Handle.html#t:Handle">Handle</a> -> <a href="../base-4.5.1.0/Data-Int.html#t:Int">Int</a> -> <a href="../base-4.5.1.0/System-IO.html#t:IO">IO</a> <a href="Data-ByteString.html#t:ByteString">ByteString</a></li><li class="src short"><a href="#v:hPut">hPut</a> :: <a href="../base-4.5.1.0/GHC-IO-Handle.html#t:Handle">Handle</a> -> <a href="Data-ByteString.html#t:ByteString">ByteString</a> -> <a href="../base-4.5.1.0/System-IO.html#t:IO">IO</a> <a href="../ghc-prim-0.2.0.0/GHC-Tuple.html#t:-40--41-">()</a></li><li class="src short"><a href="#v:hPutNonBlocking">hPutNonBlocking</a> :: <a href="../base-4.5.1.0/GHC-IO-Handle.html#t:Handle">Handle</a> -> <a href="Data-ByteString.html#t:ByteString">ByteString</a> -> <a href="../base-4.5.1.0/System-IO.html#t:IO">IO</a> <a href="Data-ByteString.html#t:ByteString">ByteString</a></li><li class="src short"><a href="#v:hPutStr">hPutStr</a> :: <a href="../base-4.5.1.0/GHC-IO-Handle.html#t:Handle">Handle</a> -> <a href="Data-ByteString.html#t:ByteString">ByteString</a> -> <a href="../base-4.5.1.0/System-IO.html#t:IO">IO</a> <a href="../ghc-prim-0.2.0.0/GHC-Tuple.html#t:-40--41-">()</a></li><li class="src short"><a href="#v:hPutStrLn">hPutStrLn</a> :: <a href="../base-4.5.1.0/GHC-IO-Handle.html#t:Handle">Handle</a> -> <a href="Data-ByteString.html#t:ByteString">ByteString</a> -> <a href="../base-4.5.1.0/System-IO.html#t:IO">IO</a> <a href="../ghc-prim-0.2.0.0/GHC-Tuple.html#t:-40--41-">()</a></li><li class="src short"><a href="#v:breakByte">breakByte</a> :: <a href="../base-4.5.1.0/Data-Word.html#t:Word8">Word8</a> -> <a href="Data-ByteString.html#t:ByteString">ByteString</a> -> (<a href="Data-ByteString.html#t:ByteString">ByteString</a>, <a href="Data-ByteString.html#t:ByteString">ByteString</a>)</li></ul></div><div id="interface"><h1 id="g:1">The <code>ByteString</code> type </h1><div class="top"><p class="src"><span class="keyword">data</span> <a name="t:ByteString" class="def">ByteString</a> </p><div class="doc"><p>A space-efficient representation of a Word8 vector, supporting many efficient operations. A <code><a href="Data-ByteString.html#t:ByteString">ByteString</a></code> contains 8-bit characters only. </p><p>Instances of Eq, Ord, Read, Show, Data, Typeable </p></div><div class="subs instances"><p id="control.i:ByteString" class="caption collapser" onclick="toggleSection('i:ByteString')">Instances</p><div id="section.i:ByteString" class="show"><table><tr><td class="src"><a href="../base-4.5.1.0/Data-Eq.html#t:Eq">Eq</a> <a href="Data-ByteString.html#t:ByteString">ByteString</a></td><td class="doc empty"> </td></tr><tr><td class="src"><a href="../base-4.5.1.0/Data-Data.html#t:Data">Data</a> <a href="Data-ByteString.html#t:ByteString">ByteString</a></td><td class="doc empty"> </td></tr><tr><td class="src"><a href="../base-4.5.1.0/Data-Ord.html#t:Ord">Ord</a> <a href="Data-ByteString.html#t:ByteString">ByteString</a></td><td class="doc empty"> </td></tr><tr><td class="src"><a href="../base-4.5.1.0/Text-Read.html#t:Read">Read</a> <a href="Data-ByteString.html#t:ByteString">ByteString</a></td><td class="doc empty"> </td></tr><tr><td class="src"><a href="../base-4.5.1.0/Text-Show.html#t:Show">Show</a> <a href="Data-ByteString.html#t:ByteString">ByteString</a></td><td class="doc empty"> </td></tr><tr><td class="src"><a href="../base-4.5.1.0/Data-Typeable-Internal.html#t:Typeable">Typeable</a> <a href="Data-ByteString.html#t:ByteString">ByteString</a></td><td class="doc empty"> </td></tr><tr><td class="src"><a href="../base-4.5.1.0/Data-String.html#t:IsString">IsString</a> <a href="Data-ByteString.html#t:ByteString">ByteString</a></td><td class="doc empty"> </td></tr><tr><td class="src"><a href="../base-4.5.1.0/Data-Monoid.html#t:Monoid">Monoid</a> <a href="Data-ByteString.html#t:ByteString">ByteString</a></td><td class="doc empty"> </td></tr></table></div></div></div><h1 id="g:2">Introducing and eliminating <code><a href="Data-ByteString.html#t:ByteString">ByteString</a></code>s </h1><div class="top"><p class="src"><a name="v:empty" class="def">empty</a> :: <a href="Data-ByteString.html#t:ByteString">ByteString</a></p><div class="doc"><p><em>O(1)</em> The empty <code><a href="Data-ByteString.html#t:ByteString">ByteString</a></code> </p></div></div><div class="top"><p class="src"><a name="v:singleton" class="def">singleton</a> :: <a href="../base-4.5.1.0/Data-Word.html#t:Word8">Word8</a> -> <a href="Data-ByteString.html#t:ByteString">ByteString</a></p><div class="doc"><p><em>O(1)</em> Convert a <code><a href="../base-4.5.1.0/Data-Word.html#t:Word8">Word8</a></code> into a <code><a href="Data-ByteString.html#t:ByteString">ByteString</a></code> </p></div></div><div class="top"><p class="src"><a name="v:pack" class="def">pack</a> :: [<a href="../base-4.5.1.0/Data-Word.html#t:Word8">Word8</a>] -> <a href="Data-ByteString.html#t:ByteString">ByteString</a></p><div class="doc"><p><em>O(n)</em> Convert a '[Word8]' into a <code><a href="Data-ByteString.html#t:ByteString">ByteString</a></code>. </p><p>For applications with large numbers of string literals, pack can be a bottleneck. In such cases, consider using packAddress (GHC only). </p></div></div><div class="top"><p class="src"><a name="v:unpack" class="def">unpack</a> :: <a href="Data-ByteString.html#t:ByteString">ByteString</a> -> [<a href="../base-4.5.1.0/Data-Word.html#t:Word8">Word8</a>]</p><div class="doc"><p><em>O(n)</em> Converts a <code><a href="Data-ByteString.html#t:ByteString">ByteString</a></code> to a '[Word8]'. </p></div></div><h1 id="g:3">Basic interface </h1><div class="top"><p class="src"><a name="v:cons" class="def">cons</a> :: <a href="../base-4.5.1.0/Data-Word.html#t:Word8">Word8</a> -> <a href="Data-ByteString.html#t:ByteString">ByteString</a> -> <a href="Data-ByteString.html#t:ByteString">ByteString</a></p><div class="doc"><p><em>O(n)</em> <code><a href="Data-ByteString.html#v:cons">cons</a></code> is analogous to (:) for lists, but of different complexity, as it requires a memcpy. </p></div></div><div class="top"><p class="src"><a name="v:snoc" class="def">snoc</a> :: <a href="Data-ByteString.html#t:ByteString">ByteString</a> -> <a href="../base-4.5.1.0/Data-Word.html#t:Word8">Word8</a> -> <a href="Data-ByteString.html#t:ByteString">ByteString</a></p><div class="doc"><p><em>O(n)</em> Append a byte to the end of a <code><a href="Data-ByteString.html#t:ByteString">ByteString</a></code> </p></div></div><div class="top"><p class="src"><a name="v:append" class="def">append</a> :: <a href="Data-ByteString.html#t:ByteString">ByteString</a> -> <a href="Data-ByteString.html#t:ByteString">ByteString</a> -> <a href="Data-ByteString.html#t:ByteString">ByteString</a></p><div class="doc"><p><em>O(n)</em> Append two ByteStrings </p></div></div><div class="top"><p class="src"><a name="v:head" class="def">head</a> :: <a href="Data-ByteString.html#t:ByteString">ByteString</a> -> <a href="../base-4.5.1.0/Data-Word.html#t:Word8">Word8</a></p><div class="doc"><p><em>O(1)</em> Extract the first element of a ByteString, which must be non-empty. An exception will be thrown in the case of an empty ByteString. </p></div></div><div class="top"><p class="src"><a name="v:uncons" class="def">uncons</a> :: <a href="Data-ByteString.html#t:ByteString">ByteString</a> -> <a href="../base-4.5.1.0/Data-Maybe.html#t:Maybe">Maybe</a> (<a href="../base-4.5.1.0/Data-Word.html#t:Word8">Word8</a>, <a href="Data-ByteString.html#t:ByteString">ByteString</a>)</p><div class="doc"><p><em>O(1)</em> Extract the head and tail of a ByteString, returning Nothing if it is empty. </p></div></div><div class="top"><p class="src"><a name="v:last" class="def">last</a> :: <a href="Data-ByteString.html#t:ByteString">ByteString</a> -> <a href="../base-4.5.1.0/Data-Word.html#t:Word8">Word8</a></p><div class="doc"><p><em>O(1)</em> Extract the last element of a ByteString, which must be finite and non-empty. An exception will be thrown in the case of an empty ByteString. </p></div></div><div class="top"><p class="src"><a name="v:tail" class="def">tail</a> :: <a href="Data-ByteString.html#t:ByteString">ByteString</a> -> <a href="Data-ByteString.html#t:ByteString">ByteString</a></p><div class="doc"><p><em>O(1)</em> Extract the elements after the head of a ByteString, which must be non-empty. An exception will be thrown in the case of an empty ByteString. </p></div></div><div class="top"><p class="src"><a name="v:init" class="def">init</a> :: <a href="Data-ByteString.html#t:ByteString">ByteString</a> -> <a href="Data-ByteString.html#t:ByteString">ByteString</a></p><div class="doc"><p><em>O(1)</em> Return all the elements of a <code><a href="Data-ByteString.html#t:ByteString">ByteString</a></code> except the last one. An exception will be thrown in the case of an empty ByteString. </p></div></div><div class="top"><p class="src"><a name="v:null" class="def">null</a> :: <a href="Data-ByteString.html#t:ByteString">ByteString</a> -> <a href="../base-4.5.1.0/Data-Bool.html#t:Bool">Bool</a></p><div class="doc"><p><em>O(1)</em> Test whether a ByteString is empty. </p></div></div><div class="top"><p class="src"><a name="v:length" class="def">length</a> :: <a href="Data-ByteString.html#t:ByteString">ByteString</a> -> <a href="../base-4.5.1.0/Data-Int.html#t:Int">Int</a></p><div class="doc"><p><em>O(1)</em> <code><a href="Data-ByteString.html#v:length">length</a></code> returns the length of a ByteString as an <code><a href="../base-4.5.1.0/Data-Int.html#t:Int">Int</a></code>. </p></div></div><h1 id="g:4">Transforming ByteStrings </h1><div class="top"><p class="src"><a name="v:map" class="def">map</a> :: (<a href="../base-4.5.1.0/Data-Word.html#t:Word8">Word8</a> -> <a href="../base-4.5.1.0/Data-Word.html#t:Word8">Word8</a>) -> <a href="Data-ByteString.html#t:ByteString">ByteString</a> -> <a href="Data-ByteString.html#t:ByteString">ByteString</a></p><div class="doc"><p><em>O(n)</em> <code><a href="Data-ByteString.html#v:map">map</a></code> <code>f xs</code> is the ByteString obtained by applying <code>f</code> to each element of <code>xs</code>. This function is subject to array fusion. </p></div></div><div class="top"><p class="src"><a name="v:reverse" class="def">reverse</a> :: <a href="Data-ByteString.html#t:ByteString">ByteString</a> -> <a href="Data-ByteString.html#t:ByteString">ByteString</a></p><div class="doc"><p><em>O(n)</em> <code><a href="Data-ByteString.html#v:reverse">reverse</a></code> <code>xs</code> efficiently returns the elements of <code>xs</code> in reverse order. </p></div></div><div class="top"><p class="src"><a name="v:intersperse" class="def">intersperse</a> :: <a href="../base-4.5.1.0/Data-Word.html#t:Word8">Word8</a> -> <a href="Data-ByteString.html#t:ByteString">ByteString</a> -> <a href="Data-ByteString.html#t:ByteString">ByteString</a></p><div class="doc"><p><em>O(n)</em> The <code><a href="Data-ByteString.html#v:intersperse">intersperse</a></code> function takes a <code><a href="../base-4.5.1.0/Data-Word.html#t:Word8">Word8</a></code> and a <code><a href="Data-ByteString.html#t:ByteString">ByteString</a></code> and `intersperses' that byte between the elements of the <code><a href="Data-ByteString.html#t:ByteString">ByteString</a></code>. It is analogous to the intersperse function on Lists. </p></div></div><div class="top"><p class="src"><a name="v:intercalate" class="def">intercalate</a> :: <a href="Data-ByteString.html#t:ByteString">ByteString</a> -> [<a href="Data-ByteString.html#t:ByteString">ByteString</a>] -> <a href="Data-ByteString.html#t:ByteString">ByteString</a></p><div class="doc"><p><em>O(n)</em> The <code><a href="Data-ByteString.html#v:intercalate">intercalate</a></code> function takes a <code><a href="Data-ByteString.html#t:ByteString">ByteString</a></code> and a list of <code><a href="Data-ByteString.html#t:ByteString">ByteString</a></code>s and concatenates the list after interspersing the first argument between each element of the list. </p></div></div><div class="top"><p class="src"><a name="v:transpose" class="def">transpose</a> :: [<a href="Data-ByteString.html#t:ByteString">ByteString</a>] -> [<a href="Data-ByteString.html#t:ByteString">ByteString</a>]</p><div class="doc"><p>The <code><a href="Data-ByteString.html#v:transpose">transpose</a></code> function transposes the rows and columns of its <code><a href="Data-ByteString.html#t:ByteString">ByteString</a></code> argument. </p></div></div><h1 id="g:5">Reducing <code><a href="Data-ByteString.html#t:ByteString">ByteString</a></code>s (folds) </h1><div class="top"><p class="src"><a name="v:foldl" class="def">foldl</a> :: (a -> <a href="../base-4.5.1.0/Data-Word.html#t:Word8">Word8</a> -> a) -> a -> <a href="Data-ByteString.html#t:ByteString">ByteString</a> -> a</p><div class="doc"><p><code><a href="Data-ByteString.html#v:foldl">foldl</a></code>, applied to a binary operator, a starting value (typically the left-identity of the operator), and a ByteString, reduces the ByteString using the binary operator, from left to right. </p><p>This function is subject to array fusion. </p></div></div><div class="top"><p class="src"><a name="v:foldl-39-" class="def">foldl'</a> :: (a -> <a href="../base-4.5.1.0/Data-Word.html#t:Word8">Word8</a> -> a) -> a -> <a href="Data-ByteString.html#t:ByteString">ByteString</a> -> a</p><div class="doc"><p>'foldl\'' is like <code><a href="Data-ByteString.html#v:foldl">foldl</a></code>, but strict in the accumulator. However, for ByteStrings, all left folds are strict in the accumulator. </p></div></div><div class="top"><p class="src"><a name="v:foldl1" class="def">foldl1</a> :: (<a href="../base-4.5.1.0/Data-Word.html#t:Word8">Word8</a> -> <a href="../base-4.5.1.0/Data-Word.html#t:Word8">Word8</a> -> <a href="../base-4.5.1.0/Data-Word.html#t:Word8">Word8</a>) -> <a href="Data-ByteString.html#t:ByteString">ByteString</a> -> <a href="../base-4.5.1.0/Data-Word.html#t:Word8">Word8</a></p><div class="doc"><p><code><a href="Data-ByteString.html#v:foldl1">foldl1</a></code> is a variant of <code><a href="Data-ByteString.html#v:foldl">foldl</a></code> that has no starting value argument, and thus must be applied to non-empty <code>ByteStrings</code>. This function is subject to array fusion. An exception will be thrown in the case of an empty ByteString. </p></div></div><div class="top"><p class="src"><a name="v:foldl1-39-" class="def">foldl1'</a> :: (<a href="../base-4.5.1.0/Data-Word.html#t:Word8">Word8</a> -> <a href="../base-4.5.1.0/Data-Word.html#t:Word8">Word8</a> -> <a href="../base-4.5.1.0/Data-Word.html#t:Word8">Word8</a>) -> <a href="Data-ByteString.html#t:ByteString">ByteString</a> -> <a href="../base-4.5.1.0/Data-Word.html#t:Word8">Word8</a></p><div class="doc"><p>'foldl1\'' is like <code><a href="Data-ByteString.html#v:foldl1">foldl1</a></code>, but strict in the accumulator. An exception will be thrown in the case of an empty ByteString. </p></div></div><div class="top"><p class="src"><a name="v:foldr" class="def">foldr</a> :: (<a href="../base-4.5.1.0/Data-Word.html#t:Word8">Word8</a> -> a -> a) -> a -> <a href="Data-ByteString.html#t:ByteString">ByteString</a> -> a</p><div class="doc"><p><code><a href="Data-ByteString.html#v:foldr">foldr</a></code>, applied to a binary operator, a starting value (typically the right-identity of the operator), and a ByteString, reduces the ByteString using the binary operator, from right to left. </p></div></div><div class="top"><p class="src"><a name="v:foldr-39-" class="def">foldr'</a> :: (<a href="../base-4.5.1.0/Data-Word.html#t:Word8">Word8</a> -> a -> a) -> a -> <a href="Data-ByteString.html#t:ByteString">ByteString</a> -> a</p><div class="doc"><p>'foldr\'' is like <code><a href="Data-ByteString.html#v:foldr">foldr</a></code>, but strict in the accumulator. </p></div></div><div class="top"><p class="src"><a name="v:foldr1" class="def">foldr1</a> :: (<a href="../base-4.5.1.0/Data-Word.html#t:Word8">Word8</a> -> <a href="../base-4.5.1.0/Data-Word.html#t:Word8">Word8</a> -> <a href="../base-4.5.1.0/Data-Word.html#t:Word8">Word8</a>) -> <a href="Data-ByteString.html#t:ByteString">ByteString</a> -> <a href="../base-4.5.1.0/Data-Word.html#t:Word8">Word8</a></p><div class="doc"><p><code><a href="Data-ByteString.html#v:foldr1">foldr1</a></code> is a variant of <code><a href="Data-ByteString.html#v:foldr">foldr</a></code> that has no starting value argument, and thus must be applied to non-empty <code><a href="Data-ByteString.html#t:ByteString">ByteString</a></code>s An exception will be thrown in the case of an empty ByteString. </p></div></div><div class="top"><p class="src"><a name="v:foldr1-39-" class="def">foldr1'</a> :: (<a href="../base-4.5.1.0/Data-Word.html#t:Word8">Word8</a> -> <a href="../base-4.5.1.0/Data-Word.html#t:Word8">Word8</a> -> <a href="../base-4.5.1.0/Data-Word.html#t:Word8">Word8</a>) -> <a href="Data-ByteString.html#t:ByteString">ByteString</a> -> <a href="../base-4.5.1.0/Data-Word.html#t:Word8">Word8</a></p><div class="doc"><p>'foldr1\'' is a variant of <code><a href="Data-ByteString.html#v:foldr1">foldr1</a></code>, but is strict in the accumulator. </p></div></div><h2 id="g:6">Special folds </h2><div class="top"><p class="src"><a name="v:concat" class="def">concat</a> :: [<a href="Data-ByteString.html#t:ByteString">ByteString</a>] -> <a href="Data-ByteString.html#t:ByteString">ByteString</a></p><div class="doc"><p><em>O(n)</em> Concatenate a list of ByteStrings. </p></div></div><div class="top"><p class="src"><a name="v:concatMap" class="def">concatMap</a> :: (<a href="../base-4.5.1.0/Data-Word.html#t:Word8">Word8</a> -> <a href="Data-ByteString.html#t:ByteString">ByteString</a>) -> <a href="Data-ByteString.html#t:ByteString">ByteString</a> -> <a href="Data-ByteString.html#t:ByteString">ByteString</a></p><div class="doc"><p>Map a function over a <code><a href="Data-ByteString.html#t:ByteString">ByteString</a></code> and concatenate the results </p></div></div><div class="top"><p class="src"><a name="v:any" class="def">any</a> :: (<a href="../base-4.5.1.0/Data-Word.html#t:Word8">Word8</a> -> <a href="../base-4.5.1.0/Data-Bool.html#t:Bool">Bool</a>) -> <a href="Data-ByteString.html#t:ByteString">ByteString</a> -> <a href="../base-4.5.1.0/Data-Bool.html#t:Bool">Bool</a></p><div class="doc"><p><em>O(n)</em> Applied to a predicate and a ByteString, <code><a href="Data-ByteString.html#v:any">any</a></code> determines if any element of the <code><a href="Data-ByteString.html#t:ByteString">ByteString</a></code> satisfies the predicate. </p></div></div><div class="top"><p class="src"><a name="v:all" class="def">all</a> :: (<a href="../base-4.5.1.0/Data-Word.html#t:Word8">Word8</a> -> <a href="../base-4.5.1.0/Data-Bool.html#t:Bool">Bool</a>) -> <a href="Data-ByteString.html#t:ByteString">ByteString</a> -> <a href="../base-4.5.1.0/Data-Bool.html#t:Bool">Bool</a></p><div class="doc"><p><em>O(n)</em> Applied to a predicate and a <code><a href="Data-ByteString.html#t:ByteString">ByteString</a></code>, <code><a href="Data-ByteString.html#v:all">all</a></code> determines if all elements of the <code><a href="Data-ByteString.html#t:ByteString">ByteString</a></code> satisfy the predicate. </p></div></div><div class="top"><p class="src"><a name="v:maximum" class="def">maximum</a> :: <a href="Data-ByteString.html#t:ByteString">ByteString</a> -> <a href="../base-4.5.1.0/Data-Word.html#t:Word8">Word8</a></p><div class="doc"><p><em>O(n)</em> <code><a href="Data-ByteString.html#v:maximum">maximum</a></code> returns the maximum value from a <code><a href="Data-ByteString.html#t:ByteString">ByteString</a></code> This function will fuse. An exception will be thrown in the case of an empty ByteString. </p></div></div><div class="top"><p class="src"><a name="v:minimum" class="def">minimum</a> :: <a href="Data-ByteString.html#t:ByteString">ByteString</a> -> <a href="../base-4.5.1.0/Data-Word.html#t:Word8">Word8</a></p><div class="doc"><p><em>O(n)</em> <code><a href="Data-ByteString.html#v:minimum">minimum</a></code> returns the minimum value from a <code><a href="Data-ByteString.html#t:ByteString">ByteString</a></code> This function will fuse. An exception will be thrown in the case of an empty ByteString. </p></div></div><h1 id="g:7">Building ByteStrings </h1><h2 id="g:8">Scans </h2><div class="top"><p class="src"><a name="v:scanl" class="def">scanl</a> :: (<a href="../base-4.5.1.0/Data-Word.html#t:Word8">Word8</a> -> <a href="../base-4.5.1.0/Data-Word.html#t:Word8">Word8</a> -> <a href="../base-4.5.1.0/Data-Word.html#t:Word8">Word8</a>) -> <a href="../base-4.5.1.0/Data-Word.html#t:Word8">Word8</a> -> <a href="Data-ByteString.html#t:ByteString">ByteString</a> -> <a href="Data-ByteString.html#t:ByteString">ByteString</a></p><div class="doc"><p><code><a href="Data-ByteString.html#v:scanl">scanl</a></code> is similar to <code><a href="Data-ByteString.html#v:foldl">foldl</a></code>, but returns a list of successive reduced values from the left. This function will fuse. </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></div></div><div class="top"><p class="src"><a name="v:scanl1" class="def">scanl1</a> :: (<a href="../base-4.5.1.0/Data-Word.html#t:Word8">Word8</a> -> <a href="../base-4.5.1.0/Data-Word.html#t:Word8">Word8</a> -> <a href="../base-4.5.1.0/Data-Word.html#t:Word8">Word8</a>) -> <a href="Data-ByteString.html#t:ByteString">ByteString</a> -> <a href="Data-ByteString.html#t:ByteString">ByteString</a></p><div class="doc"><p><code><a href="Data-ByteString.html#v:scanl1">scanl1</a></code> is a variant of <code><a href="Data-ByteString.html#v:scanl">scanl</a></code> that has no starting value argument. This function will fuse. </p><pre> scanl1 f [x1, x2, ...] == [x1, x1 `f` x2, ...] </pre></div></div><div class="top"><p class="src"><a name="v:scanr" class="def">scanr</a> :: (<a href="../base-4.5.1.0/Data-Word.html#t:Word8">Word8</a> -> <a href="../base-4.5.1.0/Data-Word.html#t:Word8">Word8</a> -> <a href="../base-4.5.1.0/Data-Word.html#t:Word8">Word8</a>) -> <a href="../base-4.5.1.0/Data-Word.html#t:Word8">Word8</a> -> <a href="Data-ByteString.html#t:ByteString">ByteString</a> -> <a href="Data-ByteString.html#t:ByteString">ByteString</a></p><div class="doc"><p>scanr is the right-to-left dual of scanl. </p></div></div><div class="top"><p class="src"><a name="v:scanr1" class="def">scanr1</a> :: (<a href="../base-4.5.1.0/Data-Word.html#t:Word8">Word8</a> -> <a href="../base-4.5.1.0/Data-Word.html#t:Word8">Word8</a> -> <a href="../base-4.5.1.0/Data-Word.html#t:Word8">Word8</a>) -> <a href="Data-ByteString.html#t:ByteString">ByteString</a> -> <a href="Data-ByteString.html#t:ByteString">ByteString</a></p><div class="doc"><p><code><a href="Data-ByteString.html#v:scanr1">scanr1</a></code> is a variant of <code><a href="Data-ByteString.html#v:scanr">scanr</a></code> that has no starting value argument. </p></div></div><h2 id="g:9">Accumulating maps </h2><div class="top"><p class="src"><a name="v:mapAccumL" class="def">mapAccumL</a> :: (acc -> <a href="../base-4.5.1.0/Data-Word.html#t:Word8">Word8</a> -> (acc, <a href="../base-4.5.1.0/Data-Word.html#t:Word8">Word8</a>)) -> acc -> <a href="Data-ByteString.html#t:ByteString">ByteString</a> -> (acc, <a href="Data-ByteString.html#t:ByteString">ByteString</a>)</p><div class="doc"><p>The <code><a href="Data-ByteString.html#v:mapAccumL">mapAccumL</a></code> function behaves like a combination of <code><a href="Data-ByteString.html#v:map">map</a></code> and <code><a href="Data-ByteString.html#v:foldl">foldl</a></code>; it applies a function to each element of a ByteString, passing an accumulating parameter from left to right, and returning a final value of this accumulator together with the new list. </p></div></div><div class="top"><p class="src"><a name="v:mapAccumR" class="def">mapAccumR</a> :: (acc -> <a href="../base-4.5.1.0/Data-Word.html#t:Word8">Word8</a> -> (acc, <a href="../base-4.5.1.0/Data-Word.html#t:Word8">Word8</a>)) -> acc -> <a href="Data-ByteString.html#t:ByteString">ByteString</a> -> (acc, <a href="Data-ByteString.html#t:ByteString">ByteString</a>)</p><div class="doc"><p>The <code><a href="Data-ByteString.html#v:mapAccumR">mapAccumR</a></code> function behaves like a combination of <code><a href="Data-ByteString.html#v:map">map</a></code> and <code><a href="Data-ByteString.html#v:foldr">foldr</a></code>; it applies a function to each element of a ByteString, passing an accumulating parameter from right to left, and returning a final value of this accumulator together with the new ByteString. </p></div></div><h2 id="g:10">Generating and unfolding ByteStrings </h2><div class="top"><p class="src"><a name="v:replicate" class="def">replicate</a> :: <a href="../base-4.5.1.0/Data-Int.html#t:Int">Int</a> -> <a href="../base-4.5.1.0/Data-Word.html#t:Word8">Word8</a> -> <a href="Data-ByteString.html#t:ByteString">ByteString</a></p><div class="doc"><p><em>O(n)</em> <code><a href="Data-ByteString.html#v:replicate">replicate</a></code> <code>n x</code> is a ByteString of length <code>n</code> with <code>x</code> the value of every element. The following holds: </p><pre> replicate w c = unfoldr w (\u -> Just (u,u)) c </pre><p>This implemenation uses <code>memset(3)</code> </p></div></div><div class="top"><p class="src"><a name="v:unfoldr" class="def">unfoldr</a> :: (a -> <a href="../base-4.5.1.0/Data-Maybe.html#t:Maybe">Maybe</a> (<a href="../base-4.5.1.0/Data-Word.html#t:Word8">Word8</a>, a)) -> a -> <a href="Data-ByteString.html#t:ByteString">ByteString</a></p><div class="doc"><p><em>O(n)</em>, where <em>n</em> is the length of the result. The <code><a href="Data-ByteString.html#v:unfoldr">unfoldr</a></code> function is analogous to the List 'unfoldr'. <code><a href="Data-ByteString.html#v:unfoldr">unfoldr</a></code> builds a ByteString from a seed value. The function takes the element and returns <code><a href="../base-4.5.1.0/Data-Maybe.html#v:Nothing">Nothing</a></code> if it is done producing the ByteString or returns <code><a href="../base-4.5.1.0/Data-Maybe.html#v:Just">Just</a></code> <code>(a,b)</code>, in which case, <code>a</code> is the next byte in the string, and <code>b</code> is the seed value for further production. </p><p>Examples: </p><pre> unfoldr (\x -> if x <= 5 then Just (x, x + 1) else Nothing) 0 == pack [0, 1, 2, 3, 4, 5] </pre></div></div><div class="top"><p class="src"><a name="v:unfoldrN" class="def">unfoldrN</a> :: <a href="../base-4.5.1.0/Data-Int.html#t:Int">Int</a> -> (a -> <a href="../base-4.5.1.0/Data-Maybe.html#t:Maybe">Maybe</a> (<a href="../base-4.5.1.0/Data-Word.html#t:Word8">Word8</a>, a)) -> a -> (<a href="Data-ByteString.html#t:ByteString">ByteString</a>, <a href="../base-4.5.1.0/Data-Maybe.html#t:Maybe">Maybe</a> a)</p><div class="doc"><p><em>O(n)</em> Like <code><a href="Data-ByteString.html#v:unfoldr">unfoldr</a></code>, <code><a href="Data-ByteString.html#v:unfoldrN">unfoldrN</a></code> builds a ByteString from a seed value. However, the length of the result is limited by the first argument to <code><a href="Data-ByteString.html#v:unfoldrN">unfoldrN</a></code>. This function is more efficient than <code><a href="Data-ByteString.html#v:unfoldr">unfoldr</a></code> when the maximum length of the result is known. </p><p>The following equation relates <code><a href="Data-ByteString.html#v:unfoldrN">unfoldrN</a></code> and <code><a href="Data-ByteString.html#v:unfoldr">unfoldr</a></code>: </p><pre> snd (unfoldrN n f s) == take n (unfoldr f s) </pre></div></div><h1 id="g:11">Substrings </h1><h2 id="g:12">Breaking strings </h2><div class="top"><p class="src"><a name="v:take" class="def">take</a> :: <a href="../base-4.5.1.0/Data-Int.html#t:Int">Int</a> -> <a href="Data-ByteString.html#t:ByteString">ByteString</a> -> <a href="Data-ByteString.html#t:ByteString">ByteString</a></p><div class="doc"><p><em>O(1)</em> <code><a href="Data-ByteString.html#v:take">take</a></code> <code>n</code>, applied to a ByteString <code>xs</code>, returns the prefix of <code>xs</code> of length <code>n</code>, or <code>xs</code> itself if <code>n > <code><a href="Data-ByteString.html#v:length">length</a></code> xs</code>. </p></div></div><div class="top"><p class="src"><a name="v:drop" class="def">drop</a> :: <a href="../base-4.5.1.0/Data-Int.html#t:Int">Int</a> -> <a href="Data-ByteString.html#t:ByteString">ByteString</a> -> <a href="Data-ByteString.html#t:ByteString">ByteString</a></p><div class="doc"><p><em>O(1)</em> <code><a href="Data-ByteString.html#v:drop">drop</a></code> <code>n xs</code> returns the suffix of <code>xs</code> after the first <code>n</code> elements, or <code>[]</code> if <code>n > <code><a href="Data-ByteString.html#v:length">length</a></code> xs</code>. </p></div></div><div class="top"><p class="src"><a name="v:splitAt" class="def">splitAt</a> :: <a href="../base-4.5.1.0/Data-Int.html#t:Int">Int</a> -> <a href="Data-ByteString.html#t:ByteString">ByteString</a> -> (<a href="Data-ByteString.html#t:ByteString">ByteString</a>, <a href="Data-ByteString.html#t:ByteString">ByteString</a>)</p><div class="doc"><p><em>O(1)</em> <code><a href="Data-ByteString.html#v:splitAt">splitAt</a></code> <code>n xs</code> is equivalent to <code>(<code><a href="Data-ByteString.html#v:take">take</a></code> n xs, <code><a href="Data-ByteString.html#v:drop">drop</a></code> n xs)</code>. </p></div></div><div class="top"><p class="src"><a name="v:takeWhile" class="def">takeWhile</a> :: (<a href="../base-4.5.1.0/Data-Word.html#t:Word8">Word8</a> -> <a href="../base-4.5.1.0/Data-Bool.html#t:Bool">Bool</a>) -> <a href="Data-ByteString.html#t:ByteString">ByteString</a> -> <a href="Data-ByteString.html#t:ByteString">ByteString</a></p><div class="doc"><p><code><a href="Data-ByteString.html#v:takeWhile">takeWhile</a></code>, applied to a predicate <code>p</code> and a ByteString <code>xs</code>, returns the longest prefix (possibly empty) of <code>xs</code> of elements that satisfy <code>p</code>. </p></div></div><div class="top"><p class="src"><a name="v:dropWhile" class="def">dropWhile</a> :: (<a href="../base-4.5.1.0/Data-Word.html#t:Word8">Word8</a> -> <a href="../base-4.5.1.0/Data-Bool.html#t:Bool">Bool</a>) -> <a href="Data-ByteString.html#t:ByteString">ByteString</a> -> <a href="Data-ByteString.html#t:ByteString">ByteString</a></p><div class="doc"><p><code><a href="Data-ByteString.html#v:dropWhile">dropWhile</a></code> <code>p xs</code> returns the suffix remaining after <code><a href="Data-ByteString.html#v:takeWhile">takeWhile</a></code> <code>p xs</code>. </p></div></div><div class="top"><p class="src"><a name="v:span" class="def">span</a> :: (<a href="../base-4.5.1.0/Data-Word.html#t:Word8">Word8</a> -> <a href="../base-4.5.1.0/Data-Bool.html#t:Bool">Bool</a>) -> <a href="Data-ByteString.html#t:ByteString">ByteString</a> -> (<a href="Data-ByteString.html#t:ByteString">ByteString</a>, <a href="Data-ByteString.html#t:ByteString">ByteString</a>)</p><div class="doc"><p><code><a href="Data-ByteString.html#v:span">span</a></code> <code>p xs</code> breaks the ByteString into two segments. It is equivalent to <code>(<code><a href="Data-ByteString.html#v:takeWhile">takeWhile</a></code> p xs, <code><a href="Data-ByteString.html#v:dropWhile">dropWhile</a></code> p xs)</code> </p></div></div><div class="top"><p class="src"><a name="v:spanEnd" class="def">spanEnd</a> :: (<a href="../base-4.5.1.0/Data-Word.html#t:Word8">Word8</a> -> <a href="../base-4.5.1.0/Data-Bool.html#t:Bool">Bool</a>) -> <a href="Data-ByteString.html#t:ByteString">ByteString</a> -> (<a href="Data-ByteString.html#t:ByteString">ByteString</a>, <a href="Data-ByteString.html#t:ByteString">ByteString</a>)</p><div class="doc"><p><code><a href="Data-ByteString.html#v:spanEnd">spanEnd</a></code> behaves like <code><a href="Data-ByteString.html#v:span">span</a></code> but from the end of the <code><a href="Data-ByteString.html#t:ByteString">ByteString</a></code>. We have </p><pre> spanEnd (not.isSpace) "x y z" == ("x y ","z") </pre><p>and </p><pre> spanEnd (not . isSpace) ps == let (x,y) = span (not.isSpace) (reverse ps) in (reverse y, reverse x) </pre></div></div><div class="top"><p class="src"><a name="v:break" class="def">break</a> :: (<a href="../base-4.5.1.0/Data-Word.html#t:Word8">Word8</a> -> <a href="../base-4.5.1.0/Data-Bool.html#t:Bool">Bool</a>) -> <a href="Data-ByteString.html#t:ByteString">ByteString</a> -> (<a href="Data-ByteString.html#t:ByteString">ByteString</a>, <a href="Data-ByteString.html#t:ByteString">ByteString</a>)</p><div class="doc"><p><code><a href="Data-ByteString.html#v:break">break</a></code> <code>p</code> is equivalent to <code><code><a href="Data-ByteString.html#v:span">span</a></code> (<code><a href="../base-4.5.1.0/Data-Bool.html#v:not">not</a></code> . p)</code>. </p><p>Under GHC, a rewrite rule will transform break (==) into a call to the specialised breakByte: </p><pre> break ((==) x) = breakByte x break (==x) = breakByte x </pre></div></div><div class="top"><p class="src"><a name="v:breakEnd" class="def">breakEnd</a> :: (<a href="../base-4.5.1.0/Data-Word.html#t:Word8">Word8</a> -> <a href="../base-4.5.1.0/Data-Bool.html#t:Bool">Bool</a>) -> <a href="Data-ByteString.html#t:ByteString">ByteString</a> -> (<a href="Data-ByteString.html#t:ByteString">ByteString</a>, <a href="Data-ByteString.html#t:ByteString">ByteString</a>)</p><div class="doc"><p><code><a href="Data-ByteString.html#v:breakEnd">breakEnd</a></code> behaves like <code><a href="Data-ByteString.html#v:break">break</a></code> but from the end of the <code><a href="Data-ByteString.html#t:ByteString">ByteString</a></code> </p><p>breakEnd p == spanEnd (not.p) </p></div></div><div class="top"><p class="src"><a name="v:group" class="def">group</a> :: <a href="Data-ByteString.html#t:ByteString">ByteString</a> -> [<a href="Data-ByteString.html#t:ByteString">ByteString</a>]</p><div class="doc"><p>The <code><a href="Data-ByteString.html#v:group">group</a></code> function takes a ByteString and returns a list of ByteStrings such that the concatenation of the result is equal to the argument. Moreover, each sublist in the result contains only equal elements. For example, </p><pre> group "Mississippi" = ["M","i","ss","i","ss","i","pp","i"] </pre><p>It is a special case of <code><a href="Data-ByteString.html#v:groupBy">groupBy</a></code>, which allows the programmer to supply their own equality test. It is about 40% faster than <em>groupBy (==)</em> </p></div></div><div class="top"><p class="src"><a name="v:groupBy" class="def">groupBy</a> :: (<a href="../base-4.5.1.0/Data-Word.html#t:Word8">Word8</a> -> <a href="../base-4.5.1.0/Data-Word.html#t:Word8">Word8</a> -> <a href="../base-4.5.1.0/Data-Bool.html#t:Bool">Bool</a>) -> <a href="Data-ByteString.html#t:ByteString">ByteString</a> -> [<a href="Data-ByteString.html#t:ByteString">ByteString</a>]</p><div class="doc"><p>The <code><a href="Data-ByteString.html#v:groupBy">groupBy</a></code> function is the non-overloaded version of <code><a href="Data-ByteString.html#v:group">group</a></code>. </p></div></div><div class="top"><p class="src"><a name="v:inits" class="def">inits</a> :: <a href="Data-ByteString.html#t:ByteString">ByteString</a> -> [<a href="Data-ByteString.html#t:ByteString">ByteString</a>]</p><div class="doc"><p><em>O(n)</em> Return all initial segments of the given <code><a href="Data-ByteString.html#t:ByteString">ByteString</a></code>, shortest first. </p></div></div><div class="top"><p class="src"><a name="v:tails" class="def">tails</a> :: <a href="Data-ByteString.html#t:ByteString">ByteString</a> -> [<a href="Data-ByteString.html#t:ByteString">ByteString</a>]</p><div class="doc"><p><em>O(n)</em> Return all final segments of the given <code><a href="Data-ByteString.html#t:ByteString">ByteString</a></code>, longest first. </p></div></div><h2 id="g:13">Breaking into many substrings </h2><div class="top"><p class="src"><a name="v:split" class="def">split</a> :: <a href="../base-4.5.1.0/Data-Word.html#t:Word8">Word8</a> -> <a href="Data-ByteString.html#t:ByteString">ByteString</a> -> [<a href="Data-ByteString.html#t:ByteString">ByteString</a>]</p><div class="doc"><p><em>O(n)</em> Break a <code><a href="Data-ByteString.html#t:ByteString">ByteString</a></code> into pieces separated by the byte argument, consuming the delimiter. I.e. </p><pre> split '\n' "a\nb\nd\ne" == ["a","b","d","e"] split 'a' "aXaXaXa" == ["","X","X","X",""] split 'x' "x" == ["",""] </pre><p>and </p><pre> intercalate [c] . split c == id split == splitWith . (==) </pre><p>As for all splitting functions in this library, this function does not copy the substrings, it just constructs new <code>ByteStrings</code> that are slices of the original. </p></div></div><div class="top"><p class="src"><a name="v:splitWith" class="def">splitWith</a> :: (<a href="../base-4.5.1.0/Data-Word.html#t:Word8">Word8</a> -> <a href="../base-4.5.1.0/Data-Bool.html#t:Bool">Bool</a>) -> <a href="Data-ByteString.html#t:ByteString">ByteString</a> -> [<a href="Data-ByteString.html#t:ByteString">ByteString</a>]</p><div class="doc"><p><em>O(n)</em> Splits a <code><a href="Data-ByteString.html#t:ByteString">ByteString</a></code> 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> splitWith (=='a') "aabbaca" == ["","","bb","c",""] splitWith (=='a') [] == [] </pre></div></div><h1 id="g:14">Predicates </h1><div class="top"><p class="src"><a name="v:isPrefixOf" class="def">isPrefixOf</a> :: <a href="Data-ByteString.html#t:ByteString">ByteString</a> -> <a href="Data-ByteString.html#t:ByteString">ByteString</a> -> <a href="../base-4.5.1.0/Data-Bool.html#t:Bool">Bool</a></p><div class="doc"><p><em>O(n)</em> The <code><a href="Data-ByteString.html#v:isPrefixOf">isPrefixOf</a></code> function takes two ByteStrings and returns <code><a href="../base-4.5.1.0/Data-Bool.html#v:True">True</a></code> iff the first is a prefix of the second. </p></div></div><div class="top"><p class="src"><a name="v:isSuffixOf" class="def">isSuffixOf</a> :: <a href="Data-ByteString.html#t:ByteString">ByteString</a> -> <a href="Data-ByteString.html#t:ByteString">ByteString</a> -> <a href="../base-4.5.1.0/Data-Bool.html#t:Bool">Bool</a></p><div class="doc"><p><em>O(n)</em> The <code><a href="Data-ByteString.html#v:isSuffixOf">isSuffixOf</a></code> function takes two ByteStrings and returns <code><a href="../base-4.5.1.0/Data-Bool.html#v:True">True</a></code> iff the first is a suffix of the second. </p><p>The following holds: </p><pre> isSuffixOf x y == reverse x `isPrefixOf` reverse y </pre><p>However, the real implemenation uses memcmp to compare the end of the string only, with no reverse required.. </p></div></div><div class="top"><p class="src"><a name="v:isInfixOf" class="def">isInfixOf</a> :: <a href="Data-ByteString.html#t:ByteString">ByteString</a> -> <a href="Data-ByteString.html#t:ByteString">ByteString</a> -> <a href="../base-4.5.1.0/Data-Bool.html#t:Bool">Bool</a></p><div class="doc"><p>Check whether one string is a substring of another. <code>isInfixOf p s</code> is equivalent to <code>not (null (findSubstrings p s))</code>. </p></div></div><h2 id="g:15">Search for arbitrary substrings </h2><div class="top"><p class="src"><a name="v:breakSubstring" class="def">breakSubstring</a></p><div class="subs arguments"><p class="caption">Arguments</p><table><tr><td class="src">:: <a href="Data-ByteString.html#t:ByteString">ByteString</a></td><td class="doc"><p>String to search for </p></td></tr><tr><td class="src">-> <a href="Data-ByteString.html#t:ByteString">ByteString</a></td><td class="doc"><p>String to search in </p></td></tr><tr><td class="src">-> (<a href="Data-ByteString.html#t:ByteString">ByteString</a>, <a href="Data-ByteString.html#t:ByteString">ByteString</a>)</td><td class="doc"><p>Head and tail of string broken at substring </p></td></tr></table></div><div class="doc"><p>Break a string on a substring, returning a pair of the part of the string prior to the match, and the rest of the string. </p><p>The following relationships hold: </p><pre> break (== c) l == breakSubstring (singleton c) l </pre><p>and: </p><pre> findSubstring s l == if null s then Just 0 else case breakSubstring s l of (x,y) | null y -> Nothing | otherwise -> Just (length x) </pre><p>For example, to tokenise a string, dropping delimiters: </p><pre> tokenise x y = h : if null t then [] else tokenise x (drop (length x) t) where (h,t) = breakSubstring x y </pre><p>To skip to the first occurence of a string: </p><pre> snd (breakSubstring x y) </pre><p>To take the parts of a string before a delimiter: </p><pre> fst (breakSubstring x y) </pre></div></div><div class="top"><p class="src"><a name="v:findSubstring" class="def">findSubstring</a></p><div class="subs arguments"><p class="caption">Arguments</p><table><tr><td class="src">:: <a href="Data-ByteString.html#t:ByteString">ByteString</a></td><td class="doc"><p>String to search for. </p></td></tr><tr><td class="src">-> <a href="Data-ByteString.html#t:ByteString">ByteString</a></td><td class="doc"><p>String to seach in. </p></td></tr><tr><td class="src">-> <a href="../base-4.5.1.0/Data-Maybe.html#t:Maybe">Maybe</a> <a href="../base-4.5.1.0/Data-Int.html#t:Int">Int</a></td><td class="doc empty"> </td></tr></table></div><div class="doc"><div class="warning"><p>Deprecated: findSubstring is deprecated in favour of breakSubstring.</p></div><p>Get the first index of a substring in another string, or <code><a href="../base-4.5.1.0/Data-Maybe.html#v:Nothing">Nothing</a></code> if the string is not found. <code>findSubstring p s</code> is equivalent to <code>listToMaybe (findSubstrings p s)</code>. </p></div></div><div class="top"><p class="src"><a name="v:findSubstrings" class="def">findSubstrings</a></p><div class="subs arguments"><p class="caption">Arguments</p><table><tr><td class="src">:: <a href="Data-ByteString.html#t:ByteString">ByteString</a></td><td class="doc"><p>String to search for. </p></td></tr><tr><td class="src">-> <a href="Data-ByteString.html#t:ByteString">ByteString</a></td><td class="doc"><p>String to seach in. </p></td></tr><tr><td class="src">-> [<a href="../base-4.5.1.0/Data-Int.html#t:Int">Int</a>]</td><td class="doc empty"> </td></tr></table></div><div class="doc"><div class="warning"><p>Deprecated: findSubstrings is deprecated in favour of breakSubstring.</p></div><p>Find the indexes of all (possibly overlapping) occurances of a substring in a string. </p></div></div><h1 id="g:16">Searching ByteStrings </h1><h2 id="g:17">Searching by equality </h2><div class="top"><p class="src"><a name="v:elem" class="def">elem</a> :: <a href="../base-4.5.1.0/Data-Word.html#t:Word8">Word8</a> -> <a href="Data-ByteString.html#t:ByteString">ByteString</a> -> <a href="../base-4.5.1.0/Data-Bool.html#t:Bool">Bool</a></p><div class="doc"><p><em>O(n)</em> <code><a href="Data-ByteString.html#v:elem">elem</a></code> is the <code><a href="Data-ByteString.html#t:ByteString">ByteString</a></code> membership predicate. </p></div></div><div class="top"><p class="src"><a name="v:notElem" class="def">notElem</a> :: <a href="../base-4.5.1.0/Data-Word.html#t:Word8">Word8</a> -> <a href="Data-ByteString.html#t:ByteString">ByteString</a> -> <a href="../base-4.5.1.0/Data-Bool.html#t:Bool">Bool</a></p><div class="doc"><p><em>O(n)</em> <code><a href="Data-ByteString.html#v:notElem">notElem</a></code> is the inverse of <code><a href="Data-ByteString.html#v:elem">elem</a></code> </p></div></div><h2 id="g:18">Searching with a predicate </h2><div class="top"><p class="src"><a name="v:find" class="def">find</a> :: (<a href="../base-4.5.1.0/Data-Word.html#t:Word8">Word8</a> -> <a href="../base-4.5.1.0/Data-Bool.html#t:Bool">Bool</a>) -> <a href="Data-ByteString.html#t:ByteString">ByteString</a> -> <a href="../base-4.5.1.0/Data-Maybe.html#t:Maybe">Maybe</a> <a href="../base-4.5.1.0/Data-Word.html#t:Word8">Word8</a></p><div class="doc"><p><em>O(n)</em> The <code><a href="Data-ByteString.html#v:find">find</a></code> function takes a predicate and a ByteString, and returns the first element in matching the predicate, or <code><a href="../base-4.5.1.0/Data-Maybe.html#v:Nothing">Nothing</a></code> if there is no such element. </p><pre> find f p = case findIndex f p of Just n -> Just (p ! n) ; _ -> Nothing </pre></div></div><div class="top"><p class="src"><a name="v:filter" class="def">filter</a> :: (<a href="../base-4.5.1.0/Data-Word.html#t:Word8">Word8</a> -> <a href="../base-4.5.1.0/Data-Bool.html#t:Bool">Bool</a>) -> <a href="Data-ByteString.html#t:ByteString">ByteString</a> -> <a href="Data-ByteString.html#t:ByteString">ByteString</a></p><div class="doc"><p><em>O(n)</em> <code><a href="Data-ByteString.html#v:filter">filter</a></code>, applied to a predicate and a ByteString, returns a ByteString containing those characters that satisfy the predicate. This function is subject to array fusion. </p></div></div><div class="top"><p class="src"><a name="v:partition" class="def">partition</a> :: (<a href="../base-4.5.1.0/Data-Word.html#t:Word8">Word8</a> -> <a href="../base-4.5.1.0/Data-Bool.html#t:Bool">Bool</a>) -> <a href="Data-ByteString.html#t:ByteString">ByteString</a> -> (<a href="Data-ByteString.html#t:ByteString">ByteString</a>, <a href="Data-ByteString.html#t:ByteString">ByteString</a>)</p><div class="doc"><p><em>O(n)</em> The <code><a href="Data-ByteString.html#v:partition">partition</a></code> function takes a predicate a ByteString and returns the pair of ByteStrings with elements which do and do not satisfy the predicate, respectively; i.e., </p><pre> partition p bs == (filter p xs, filter (not . p) xs) </pre></div></div><h1 id="g:19">Indexing ByteStrings </h1><div class="top"><p class="src"><a name="v:index" class="def">index</a> :: <a href="Data-ByteString.html#t:ByteString">ByteString</a> -> <a href="../base-4.5.1.0/Data-Int.html#t:Int">Int</a> -> <a href="../base-4.5.1.0/Data-Word.html#t:Word8">Word8</a></p><div class="doc"><p><em>O(1)</em> <code><a href="Data-ByteString.html#t:ByteString">ByteString</a></code> index (subscript) operator, starting from 0. </p></div></div><div class="top"><p class="src"><a name="v:elemIndex" class="def">elemIndex</a> :: <a href="../base-4.5.1.0/Data-Word.html#t:Word8">Word8</a> -> <a href="Data-ByteString.html#t:ByteString">ByteString</a> -> <a href="../base-4.5.1.0/Data-Maybe.html#t:Maybe">Maybe</a> <a href="../base-4.5.1.0/Data-Int.html#t:Int">Int</a></p><div class="doc"><p><em>O(n)</em> The <code><a href="Data-ByteString.html#v:elemIndex">elemIndex</a></code> function returns the index of the first element in the given <code><a href="Data-ByteString.html#t:ByteString">ByteString</a></code> which is equal to the query element, or <code><a href="../base-4.5.1.0/Data-Maybe.html#v:Nothing">Nothing</a></code> if there is no such element. This implementation uses memchr(3). </p></div></div><div class="top"><p class="src"><a name="v:elemIndices" class="def">elemIndices</a> :: <a href="../base-4.5.1.0/Data-Word.html#t:Word8">Word8</a> -> <a href="Data-ByteString.html#t:ByteString">ByteString</a> -> [<a href="../base-4.5.1.0/Data-Int.html#t:Int">Int</a>]</p><div class="doc"><p><em>O(n)</em> The <code><a href="Data-ByteString.html#v:elemIndices">elemIndices</a></code> function extends <code><a href="Data-ByteString.html#v:elemIndex">elemIndex</a></code>, by returning the indices of all elements equal to the query element, in ascending order. This implementation uses memchr(3). </p></div></div><div class="top"><p class="src"><a name="v:elemIndexEnd" class="def">elemIndexEnd</a> :: <a href="../base-4.5.1.0/Data-Word.html#t:Word8">Word8</a> -> <a href="Data-ByteString.html#t:ByteString">ByteString</a> -> <a href="../base-4.5.1.0/Data-Maybe.html#t:Maybe">Maybe</a> <a href="../base-4.5.1.0/Data-Int.html#t:Int">Int</a></p><div class="doc"><p><em>O(n)</em> The <code><a href="Data-ByteString.html#v:elemIndexEnd">elemIndexEnd</a></code> function returns the last index of the element in the given <code><a href="Data-ByteString.html#t:ByteString">ByteString</a></code> which is equal to the query element, or <code><a href="../base-4.5.1.0/Data-Maybe.html#v:Nothing">Nothing</a></code> if there is no such element. The following holds: </p><pre> elemIndexEnd c xs == (-) (length xs - 1) `fmap` elemIndex c (reverse xs) </pre></div></div><div class="top"><p class="src"><a name="v:findIndex" class="def">findIndex</a> :: (<a href="../base-4.5.1.0/Data-Word.html#t:Word8">Word8</a> -> <a href="../base-4.5.1.0/Data-Bool.html#t:Bool">Bool</a>) -> <a href="Data-ByteString.html#t:ByteString">ByteString</a> -> <a href="../base-4.5.1.0/Data-Maybe.html#t:Maybe">Maybe</a> <a href="../base-4.5.1.0/Data-Int.html#t:Int">Int</a></p><div class="doc"><p>The <code><a href="Data-ByteString.html#v:findIndex">findIndex</a></code> function takes a predicate and a <code><a href="Data-ByteString.html#t:ByteString">ByteString</a></code> and returns the index of the first element in the ByteString satisfying the predicate. </p></div></div><div class="top"><p class="src"><a name="v:findIndices" class="def">findIndices</a> :: (<a href="../base-4.5.1.0/Data-Word.html#t:Word8">Word8</a> -> <a href="../base-4.5.1.0/Data-Bool.html#t:Bool">Bool</a>) -> <a href="Data-ByteString.html#t:ByteString">ByteString</a> -> [<a href="../base-4.5.1.0/Data-Int.html#t:Int">Int</a>]</p><div class="doc"><p>The <code><a href="Data-ByteString.html#v:findIndices">findIndices</a></code> function extends <code><a href="Data-ByteString.html#v:findIndex">findIndex</a></code>, by returning the indices of all elements satisfying the predicate, in ascending order. </p></div></div><div class="top"><p class="src"><a name="v:count" class="def">count</a> :: <a href="../base-4.5.1.0/Data-Word.html#t:Word8">Word8</a> -> <a href="Data-ByteString.html#t:ByteString">ByteString</a> -> <a href="../base-4.5.1.0/Data-Int.html#t:Int">Int</a></p><div class="doc"><p>count returns the number of times its argument appears in the ByteString </p><pre> count = length . elemIndices </pre><p>But more efficiently than using length on the intermediate list. </p></div></div><h1 id="g:20">Zipping and unzipping ByteStrings </h1><div class="top"><p class="src"><a name="v:zip" class="def">zip</a> :: <a href="Data-ByteString.html#t:ByteString">ByteString</a> -> <a href="Data-ByteString.html#t:ByteString">ByteString</a> -> [(<a href="../base-4.5.1.0/Data-Word.html#t:Word8">Word8</a>, <a href="../base-4.5.1.0/Data-Word.html#t:Word8">Word8</a>)]</p><div class="doc"><p><em>O(n)</em> <code><a href="Data-ByteString.html#v:zip">zip</a></code> takes two ByteStrings and returns a list of corresponding pairs of bytes. If one input ByteString is short, excess elements of the longer ByteString are discarded. This is equivalent to a pair of <code><a href="Data-ByteString.html#v:unpack">unpack</a></code> operations. </p></div></div><div class="top"><p class="src"><a name="v:zipWith" class="def">zipWith</a> :: (<a href="../base-4.5.1.0/Data-Word.html#t:Word8">Word8</a> -> <a href="../base-4.5.1.0/Data-Word.html#t:Word8">Word8</a> -> a) -> <a href="Data-ByteString.html#t:ByteString">ByteString</a> -> <a href="Data-ByteString.html#t:ByteString">ByteString</a> -> [a]</p><div class="doc"><p><code><a href="Data-ByteString.html#v:zipWith">zipWith</a></code> generalises <code><a href="Data-ByteString.html#v:zip">zip</a></code> by zipping with the function given as the first argument, instead of a tupling function. For example, <code><code><a href="Data-ByteString.html#v:zipWith">zipWith</a></code> (+)</code> is applied to two ByteStrings to produce the list of corresponding sums. </p></div></div><div class="top"><p class="src"><a name="v:unzip" class="def">unzip</a> :: [(<a href="../base-4.5.1.0/Data-Word.html#t:Word8">Word8</a>, <a href="../base-4.5.1.0/Data-Word.html#t:Word8">Word8</a>)] -> (<a href="Data-ByteString.html#t:ByteString">ByteString</a>, <a href="Data-ByteString.html#t:ByteString">ByteString</a>)</p><div class="doc"><p><em>O(n)</em> <code><a href="Data-ByteString.html#v:unzip">unzip</a></code> transforms a list of pairs of bytes into a pair of ByteStrings. Note that this performs two <code><a href="Data-ByteString.html#v:pack">pack</a></code> operations. </p></div></div><h1 id="g:21">Ordered ByteStrings </h1><div class="top"><p class="src"><a name="v:sort" class="def">sort</a> :: <a href="Data-ByteString.html#t:ByteString">ByteString</a> -> <a href="Data-ByteString.html#t:ByteString">ByteString</a></p><div class="doc"><p><em>O(n)</em> Sort a ByteString efficiently, using counting sort. </p></div></div><h1 id="g:22">Low level conversions </h1><h2 id="g:23">Copying ByteStrings </h2><div class="top"><p class="src"><a name="v:copy" class="def">copy</a> :: <a href="Data-ByteString.html#t:ByteString">ByteString</a> -> <a href="Data-ByteString.html#t:ByteString">ByteString</a></p><div class="doc"><p><em>O(n)</em> Make a copy of the <code><a href="Data-ByteString.html#t:ByteString">ByteString</a></code> with its own storage. This is mainly useful to allow the rest of the data pointed to by the <code><a href="Data-ByteString.html#t:ByteString">ByteString</a></code> to be garbage collected, for example if a large string has been read in, and only a small part of it is needed in the rest of the program. </p></div></div><h2 id="g:24">Packing <code><a href="../base-4.5.1.0/Foreign-C-String.html#t:CString">CString</a></code>s and pointers </h2><div class="top"><p class="src"><a name="v:packCString" class="def">packCString</a> :: <a href="../base-4.5.1.0/Foreign-C-String.html#t:CString">CString</a> -> <a href="../base-4.5.1.0/System-IO.html#t:IO">IO</a> <a href="Data-ByteString.html#t:ByteString">ByteString</a></p><div class="doc"><p><em>O(n).</em> Construct a new <code>ByteString</code> from a <code>CString</code>. The resulting <code>ByteString</code> is an immutable copy of the original <code>CString</code>, and is managed on the Haskell heap. The original <code>CString</code> must be null terminated. </p></div></div><div class="top"><p class="src"><a name="v:packCStringLen" class="def">packCStringLen</a> :: <a href="../base-4.5.1.0/Foreign-C-String.html#t:CStringLen">CStringLen</a> -> <a href="../base-4.5.1.0/System-IO.html#t:IO">IO</a> <a href="Data-ByteString.html#t:ByteString">ByteString</a></p><div class="doc"><p><em>O(n).</em> Construct a new <code>ByteString</code> from a <code>CStringLen</code>. The resulting <code>ByteString</code> is an immutable copy of the original <code>CStringLen</code>. The <code>ByteString</code> is a normal Haskell value and will be managed on the Haskell heap. </p></div></div><h2 id="g:25">Using ByteStrings as <code><a href="../base-4.5.1.0/Foreign-C-String.html#t:CString">CString</a></code>s </h2><div class="top"><p class="src"><a name="v:useAsCString" class="def">useAsCString</a> :: <a href="Data-ByteString.html#t:ByteString">ByteString</a> -> (<a href="../base-4.5.1.0/Foreign-C-String.html#t:CString">CString</a> -> <a href="../base-4.5.1.0/System-IO.html#t:IO">IO</a> a) -> <a href="../base-4.5.1.0/System-IO.html#t:IO">IO</a> a</p><div class="doc"><p><em>O(n) construction</em> Use a <code>ByteString</code> with a function requiring a null-terminated <code>CString</code>. The <code>CString</code> will be freed automatically. This is a memcpy(3). </p></div></div><div class="top"><p class="src"><a name="v:useAsCStringLen" class="def">useAsCStringLen</a> :: <a href="Data-ByteString.html#t:ByteString">ByteString</a> -> (<a href="../base-4.5.1.0/Foreign-C-String.html#t:CStringLen">CStringLen</a> -> <a href="../base-4.5.1.0/System-IO.html#t:IO">IO</a> a) -> <a href="../base-4.5.1.0/System-IO.html#t:IO">IO</a> a</p><div class="doc"><p><em>O(n) construction</em> Use a <code>ByteString</code> with a function requiring a <code>CStringLen</code>. As for <code>useAsCString</code> this function makes a copy of the original <code>ByteString</code>. </p></div></div><h1 id="g:26">I/O with <code><a href="Data-ByteString.html#t:ByteString">ByteString</a></code>s </h1><h2 id="g:27">Standard input and output </h2><div class="top"><p class="src"><a name="v:getLine" class="def">getLine</a> :: <a href="../base-4.5.1.0/System-IO.html#t:IO">IO</a> <a href="Data-ByteString.html#t:ByteString">ByteString</a></p><div class="doc"><p>Read a line from stdin. </p></div></div><div class="top"><p class="src"><a name="v:getContents" class="def">getContents</a> :: <a href="../base-4.5.1.0/System-IO.html#t:IO">IO</a> <a href="Data-ByteString.html#t:ByteString">ByteString</a></p><div class="doc"><p>getContents. Read stdin strictly. Equivalent to hGetContents stdin The <code><a href="../base-4.5.1.0/GHC-IO-Handle.html#t:Handle">Handle</a></code> is closed after the contents have been read. </p></div></div><div class="top"><p class="src"><a name="v:putStr" class="def">putStr</a> :: <a href="Data-ByteString.html#t:ByteString">ByteString</a> -> <a href="../base-4.5.1.0/System-IO.html#t:IO">IO</a> <a href="../ghc-prim-0.2.0.0/GHC-Tuple.html#t:-40--41-">()</a></p><div class="doc"><p>Write a ByteString to stdout </p></div></div><div class="top"><p class="src"><a name="v:putStrLn" class="def">putStrLn</a> :: <a href="Data-ByteString.html#t:ByteString">ByteString</a> -> <a href="../base-4.5.1.0/System-IO.html#t:IO">IO</a> <a href="../ghc-prim-0.2.0.0/GHC-Tuple.html#t:-40--41-">()</a></p><div class="doc"><div class="warning"><p>Deprecated: Use Data.ByteString.Char8.putStrLn instead. (Functions that rely on ASCII encodings belong in Data.ByteString.Char8)</p></div><p>Write a ByteString to stdout, appending a newline byte </p></div></div><div class="top"><p class="src"><a name="v:interact" class="def">interact</a> :: (<a href="Data-ByteString.html#t:ByteString">ByteString</a> -> <a href="Data-ByteString.html#t:ByteString">ByteString</a>) -> <a href="../base-4.5.1.0/System-IO.html#t:IO">IO</a> <a href="../ghc-prim-0.2.0.0/GHC-Tuple.html#t:-40--41-">()</a></p><div class="doc"><p>The interact function takes a function of type <code>ByteString -> ByteString</code> as its argument. The entire input from the standard input device is passed to this function as its argument, and the resulting string is output on the standard output device. </p></div></div><h2 id="g:28">Files </h2><div class="top"><p class="src"><a name="v:readFile" class="def">readFile</a> :: <a href="../base-4.5.1.0/System-IO.html#t:FilePath">FilePath</a> -> <a href="../base-4.5.1.0/System-IO.html#t:IO">IO</a> <a href="Data-ByteString.html#t:ByteString">ByteString</a></p><div class="doc"><p>Read an entire file strictly into a <code><a href="Data-ByteString.html#t:ByteString">ByteString</a></code>. This is far more efficient than reading the characters into a <code><a href="../base-4.5.1.0/Data-String.html#t:String">String</a></code> and then using <code><a href="Data-ByteString.html#v:pack">pack</a></code>. It also may be more efficient than opening the file and reading it using hGet. Files are read using 'binary mode' on Windows, for 'text mode' use the Char8 version of this function. </p></div></div><div class="top"><p class="src"><a name="v:writeFile" class="def">writeFile</a> :: <a href="../base-4.5.1.0/System-IO.html#t:FilePath">FilePath</a> -> <a href="Data-ByteString.html#t:ByteString">ByteString</a> -> <a href="../base-4.5.1.0/System-IO.html#t:IO">IO</a> <a href="../ghc-prim-0.2.0.0/GHC-Tuple.html#t:-40--41-">()</a></p><div class="doc"><p>Write a <code><a href="Data-ByteString.html#t:ByteString">ByteString</a></code> to a file. </p></div></div><div class="top"><p class="src"><a name="v:appendFile" class="def">appendFile</a> :: <a href="../base-4.5.1.0/System-IO.html#t:FilePath">FilePath</a> -> <a href="Data-ByteString.html#t:ByteString">ByteString</a> -> <a href="../base-4.5.1.0/System-IO.html#t:IO">IO</a> <a href="../ghc-prim-0.2.0.0/GHC-Tuple.html#t:-40--41-">()</a></p><div class="doc"><p>Append a <code><a href="Data-ByteString.html#t:ByteString">ByteString</a></code> to a file. </p></div></div><h2 id="g:29">I/O with Handles </h2><div class="top"><p class="src"><a name="v:hGetLine" class="def">hGetLine</a> :: <a href="../base-4.5.1.0/GHC-IO-Handle.html#t:Handle">Handle</a> -> <a href="../base-4.5.1.0/System-IO.html#t:IO">IO</a> <a href="Data-ByteString.html#t:ByteString">ByteString</a></p><div class="doc"><p>Read a line from a handle </p></div></div><div class="top"><p class="src"><a name="v:hGetContents" class="def">hGetContents</a> :: <a href="../base-4.5.1.0/GHC-IO-Handle.html#t:Handle">Handle</a> -> <a href="../base-4.5.1.0/System-IO.html#t:IO">IO</a> <a href="Data-ByteString.html#t:ByteString">ByteString</a></p><div class="doc"><p>Read entire handle contents strictly into a <code><a href="Data-ByteString.html#t:ByteString">ByteString</a></code>. </p><p>This function reads chunks at a time, doubling the chunksize on each read. The final buffer is then realloced to the appropriate size. For files > half of available memory, this may lead to memory exhaustion. Consider using <code><a href="Data-ByteString.html#v:readFile">readFile</a></code> in this case. </p><p>As with <code><a href="Data-ByteString.html#v:hGet">hGet</a></code>, the string representation in the file is assumed to be ISO-8859-1. </p><p>The Handle is closed once the contents have been read, or if an exception is thrown. </p></div></div><div class="top"><p class="src"><a name="v:hGet" class="def">hGet</a> :: <a href="../base-4.5.1.0/GHC-IO-Handle.html#t:Handle">Handle</a> -> <a href="../base-4.5.1.0/Data-Int.html#t:Int">Int</a> -> <a href="../base-4.5.1.0/System-IO.html#t:IO">IO</a> <a href="Data-ByteString.html#t:ByteString">ByteString</a></p><div class="doc"><p>Read a <code><a href="Data-ByteString.html#t:ByteString">ByteString</a></code> directly from the specified <code><a href="../base-4.5.1.0/GHC-IO-Handle.html#t:Handle">Handle</a></code>. This is far more efficient than reading the characters into a <code><a href="../base-4.5.1.0/Data-String.html#t:String">String</a></code> and then using <code><a href="Data-ByteString.html#v:pack">pack</a></code>. First argument is the Handle to read from, and the second is the number of bytes to read. It returns the bytes read, up to n, or <code><a href="Data-ByteString.html#v:null">null</a></code> if EOF has been reached. </p><p><code><a href="Data-ByteString.html#v:hGet">hGet</a></code> is implemented in terms of <code><a href="../base-4.5.1.0/GHC-IO-Handle.html#v:hGetBuf">hGetBuf</a></code>. </p><p>If the handle is a pipe or socket, and the writing end is closed, <code><a href="Data-ByteString.html#v:hGet">hGet</a></code> will behave as if EOF was reached. </p></div></div><div class="top"><p class="src"><a name="v:hGetSome" class="def">hGetSome</a> :: <a href="../base-4.5.1.0/GHC-IO-Handle.html#t:Handle">Handle</a> -> <a href="../base-4.5.1.0/Data-Int.html#t:Int">Int</a> -> <a href="../base-4.5.1.0/System-IO.html#t:IO">IO</a> <a href="Data-ByteString.html#t:ByteString">ByteString</a></p><div class="doc"><p>Like <code><a href="Data-ByteString.html#v:hGet">hGet</a></code>, except that a shorter <code><a href="Data-ByteString.html#t:ByteString">ByteString</a></code> may be returned if there are not enough bytes immediately available to satisfy the whole request. <code><a href="Data-ByteString.html#v:hGetSome">hGetSome</a></code> only blocks if there is no data available, and EOF has not yet been reached. </p></div></div><div class="top"><p class="src"><a name="v:hGetNonBlocking" class="def">hGetNonBlocking</a> :: <a href="../base-4.5.1.0/GHC-IO-Handle.html#t:Handle">Handle</a> -> <a href="../base-4.5.1.0/Data-Int.html#t:Int">Int</a> -> <a href="../base-4.5.1.0/System-IO.html#t:IO">IO</a> <a href="Data-ByteString.html#t:ByteString">ByteString</a></p><div class="doc"><p>hGetNonBlocking is similar to <code><a href="Data-ByteString.html#v:hGet">hGet</a></code>, except that it will never block waiting for data to become available, instead it returns only whatever data is available. If there is no data available to be read, <code><a href="Data-ByteString.html#v:hGetNonBlocking">hGetNonBlocking</a></code> returns <code><a href="Data-ByteString.html#v:empty">empty</a></code>. </p><p>Note: on Windows and with Haskell implementation other than GHC, this function does not work correctly; it behaves identically to <code><a href="Data-ByteString.html#v:hGet">hGet</a></code>. </p></div></div><div class="top"><p class="src"><a name="v:hPut" class="def">hPut</a> :: <a href="../base-4.5.1.0/GHC-IO-Handle.html#t:Handle">Handle</a> -> <a href="Data-ByteString.html#t:ByteString">ByteString</a> -> <a href="../base-4.5.1.0/System-IO.html#t:IO">IO</a> <a href="../ghc-prim-0.2.0.0/GHC-Tuple.html#t:-40--41-">()</a></p><div class="doc"><p>Outputs a <code><a href="Data-ByteString.html#t:ByteString">ByteString</a></code> to the specified <code><a href="../base-4.5.1.0/GHC-IO-Handle.html#t:Handle">Handle</a></code>. </p></div></div><div class="top"><p class="src"><a name="v:hPutNonBlocking" class="def">hPutNonBlocking</a> :: <a href="../base-4.5.1.0/GHC-IO-Handle.html#t:Handle">Handle</a> -> <a href="Data-ByteString.html#t:ByteString">ByteString</a> -> <a href="../base-4.5.1.0/System-IO.html#t:IO">IO</a> <a href="Data-ByteString.html#t:ByteString">ByteString</a></p><div class="doc"><p>Similar to <code><a href="Data-ByteString.html#v:hPut">hPut</a></code> except that it will never block. Instead it returns any tail that did not get written. This tail may be <code><a href="Data-ByteString.html#v:empty">empty</a></code> in the case that the whole string was written, or the whole original string if nothing was written. Partial writes are also possible. </p><p>Note: on Windows and with Haskell implementation other than GHC, this function does not work correctly; it behaves identically to <code><a href="Data-ByteString.html#v:hPut">hPut</a></code>. </p></div></div><div class="top"><p class="src"><a name="v:hPutStr" class="def">hPutStr</a> :: <a href="../base-4.5.1.0/GHC-IO-Handle.html#t:Handle">Handle</a> -> <a href="Data-ByteString.html#t:ByteString">ByteString</a> -> <a href="../base-4.5.1.0/System-IO.html#t:IO">IO</a> <a href="../ghc-prim-0.2.0.0/GHC-Tuple.html#t:-40--41-">()</a></p><div class="doc"><p>A synonym for <code>hPut</code>, for compatibility </p></div></div><div class="top"><p class="src"><a name="v:hPutStrLn" class="def">hPutStrLn</a> :: <a href="../base-4.5.1.0/GHC-IO-Handle.html#t:Handle">Handle</a> -> <a href="Data-ByteString.html#t:ByteString">ByteString</a> -> <a href="../base-4.5.1.0/System-IO.html#t:IO">IO</a> <a href="../ghc-prim-0.2.0.0/GHC-Tuple.html#t:-40--41-">()</a></p><div class="doc"><div class="warning"><p>Deprecated: Use Data.ByteString.Char8.hPutStrLn instead. (Functions that rely on ASCII encodings belong in Data.ByteString.Char8)</p></div><p>Write a ByteString to a handle, appending a newline byte </p></div></div><div class="top"><p class="src"><a name="v:breakByte" class="def">breakByte</a> :: <a href="../base-4.5.1.0/Data-Word.html#t:Word8">Word8</a> -> <a href="Data-ByteString.html#t:ByteString">ByteString</a> -> (<a href="Data-ByteString.html#t:ByteString">ByteString</a>, <a href="Data-ByteString.html#t:ByteString">ByteString</a>)</p><div class="doc"><p><code><a href="Data-ByteString.html#v:breakByte">breakByte</a></code> breaks its ByteString argument at the first occurence of the specified byte. It is more efficient than <code><a href="Data-ByteString.html#v:break">break</a></code> as it is implemented with <code>memchr(3)</code>. I.e. </p><pre> break (=='c') "abcd" == breakByte 'c' "abcd" </pre></div></div></div></div><div id="footer"><p>Produced by <a href="http://www.haskell.org/haddock/">Haddock</a> version 2.11.0</p></div></body></html>