cons package:rio
O(n) cons is analogous to (:) for lists, but of
different complexity, as it requires making a copy.
O(1) cons is analogous to
(:) for lists.
O(n) Adds a character to the front of a
Text. This
function is more costly than its
List counterpart because it
requires copying a new array. Subject to fusion. Performs replacement
on invalid scalar values.
O(1) Adds a character to the front of a
Text. Subject to
fusion.
O(1) Unlike
cons,
cons' is strict in the
ByteString that we are consing onto. More precisely, it forces the
head and the first chunk. It does this because, for space efficiency,
it may coalesce the new byte onto the first 'chunk' rather than
starting a new 'chunk'.
So that means you can't use a lazy recursive contruction like this:
let xs = cons' c xs in xs
You can however use
cons, as well as
repeat and
cycle, to build infinite lazy ByteStrings.
const x is a unary function which evaluates to
x for
all inputs.
>>> const 42 "hello"
42
>>> map (const 42) [0..3]
[42,42,42,42]
O(n) Construct a vector with
n elements by repeatedly
applying the generator function to the already constructed part of the
vector.
constructN 3 f = let a = f <> ; b = f <a> ; c = f <a,b> in <a,b,c>
O(n) Construct a vector with
n elements from right to
left by repeatedly applying the generator function to the already
constructed part of the vector.
constructrN 3 f = let a = f <> ; b = f<a> ; c = f <b,a> in <c,b,a>
O(n) Construct a vector with
n elements by repeatedly
applying the generator function to the already constructed part of the
vector.
constructN 3 f = let a = f <> ; b = f <a> ; c = f <a,b> in <a,b,c>
O(n) Construct a vector with
n elements from right to
left by repeatedly applying the generator function to the already
constructed part of the vector.
constructrN 3 f = let a = f <> ; b = f<a> ; c = f <b,a> in <c,b,a>
O(n) Construct a vector with
n elements by repeatedly
applying the generator function to the already constructed part of the
vector.
constructN 3 f = let a = f <> ; b = f <a> ; c = f <a,b> in <a,b,c>
O(n) Construct a vector with
n elements from right to
left by repeatedly applying the generator function to the already
constructed part of the vector.
constructrN 3 f = let a = f <> ; b = f<a> ; c = f <b,a> in <c,b,a>
O(n) Construct a vector with
n elements by repeatedly
applying the generator function to the already constructed part of the
vector.
constructN 3 f = let a = f <> ; b = f <a> ; c = f <a,b> in <a,b,c>
O(n) Construct a vector with
n elements from right to
left by repeatedly applying the generator function to the already
constructed part of the vector.
constructrN 3 f = let a = f <> ; b = f<a> ; c = f <b,a> in <c,b,a>
O(1) Extract the head and tail of a ByteString, returning
Nothing if it is empty.
Decompose a list into its head and tail. If the list is
empty, returns
Nothing. If the list is non-empty, returns
Just (x, xs), where
x is the head of the list
and
xs its tail.
uncons produces the first element of the stream, and a stream
of the remaining elements, if any.