Data.ByteString
- Package
- purescript-bytestrings
- Repository
- f-f/purescript-bytestrings
This module defines a type of immutable byte strings, and associated
helper functions and type class instances. String conversions live in
Data.ByteString.Encoding, mutation in Data.ByteString.ST.
#ByteString Source
data ByteStringAn immutable sequence of bytes.
Eq and Ord compare bytewise, ordering lexicographically. show
renders the bytes as lowercase hex, e.g. ByteString "6869"
Instances
#empty Source
empty :: ByteStringThe empty byte string.
#pack Source
pack :: Array Byte -> ByteStringCreate a byte string from an array of byte values.
Running time: O(n)
#index Source
index :: ByteString -> Int -> Maybe ByteRead the byte at the given index, returning Nothing if the index is out
of range.
Running time: O(1)
#unsafeIndex Source
unsafeIndex :: ByteString -> Int -> ByteRead the byte at the given index, throwing an exception if the index is
out of range. It is the caller's responsibility to ensure the index is in
bounds; use index for safe access.
#uncons Source
uncons :: ByteString -> Maybe { head :: Byte, tail :: ByteString }Split off the first byte, returning it together with the remaining bytes,
or Nothing if the byte string is empty.
Running time: O(n)
#unsnoc Source
unsnoc :: ByteString -> Maybe { init :: ByteString, last :: Byte }Split off the last byte, returning the leading bytes together with it, or
Nothing if the byte string is empty.
Running time: O(n)
#head Source
head :: ByteString -> Maybe ByteGet the first byte, or Nothing if the byte string is empty.
Running time: O(1)
#last Source
last :: ByteString -> Maybe ByteGet the last byte, or Nothing if the byte string is empty.
Running time: O(1)
#foldl Source
foldl :: forall a. (a -> Byte -> a) -> a -> ByteString -> aFold over the bytes left-to-right (first byte first).
#foldr Source
foldr :: forall a. (Byte -> a -> a) -> a -> ByteString -> aFold over the bytes right-to-left (last byte first).
#foldMap Source
foldMap :: forall m. Monoid m => (Byte -> m) -> ByteString -> mMap each byte to a monoid and combine the results in byte order
(left-to-right, matching foldl).
#slice Source
slice :: Int -> Int -> ByteString -> ByteStringExtract the sub-range [start, end) as a new byte string. Indices are
clamped into range, so this never fails.
slice 1 3 (bytes [ 1, 2, 3 ]) == bytes [ 2, 3 ]
Running time: O(n)
#take Source
take :: Int -> ByteString -> ByteStringTake the first n bytes as a new byte string. Does not fail.
Running time: O(n)
#drop Source
drop :: Int -> ByteString -> ByteStringDrop the first n bytes, returning the rest as a new byte string.
Does not fail.
Running time: O(n)