foldr package:text

O(n) foldr, applied to a binary operator, a starting value (typically the right-identity of the operator), and a Text, reduces the Text using the binary operator, from right to left. If the binary operator is strict in its second argument, use foldr' instead. foldr is lazy like foldr for lists: evaluation actually traverses the Text from left to right, only as far as it needs to. For example, head can be defined with O(1) complexity using foldr:
head :: Text -> Char
head = foldr const (error "head empty")
Searches from left to right with short-circuiting behavior can also be defined using foldr (e.g., any, all, find, elem).
foldr, applied to a binary operator, a starting value (typically the right-identity of the operator), and a stream, reduces the stream using the binary operator, from right to left. Properties
foldr f z0 . stream = foldr f z0
O(n) foldr, applied to a binary operator, a starting value (typically the right-identity of the operator), and a Text, reduces the Text using the binary operator, from right to left. foldr is lazy like foldr for lists: evaluation actually traverses the Text from left to right, only as far as it needs to. For example, head can be defined with O(1) complexity using foldr:
head :: Text -> Char
head = foldr const (error "head empty")
O(n) A strict version of foldr. foldr' evaluates as a right-to-left traversal using constant stack space.
O(n) A variant of foldr that has no starting value argument, and thus must be applied to a non-empty Text.
foldr1 is a variant of foldr that has no starting value argument, and thus must be applied to non-empty streams. Properties
foldr1 f . stream = foldr1 f
Consume the chunks of a lazy Text with a natural right fold.
O(n), where n is the length of the result. The unfoldr function is analogous to the List unfoldr. unfoldr builds a Text from a seed value. The function takes the element and returns Nothing if it is done producing the Text, otherwise Just (a,b). In this case, a is the next Char in the string, and b is the seed value for further production. Performs replacement on invalid scalar values.
O(n) Like unfoldr, unfoldrN builds a Text from a seed value. However, the length of the result should be limited by the first argument to unfoldrN. This function is more efficient than unfoldr when the maximum length of the result is known and correct, otherwise its performance is similar to unfoldr. Performs replacement on invalid scalar values.
O(n) Like unfoldr, unfoldrN builds a stream from a seed value. However, the length of the result is limited by the first argument to unfoldrN. This function is more efficient than unfoldr when the length of the result is known. Properties
unstream (unfoldrN n f a) = unfoldrN n f a
O(n), where n is the length of the result. The unfoldr function is analogous to the List unfoldr. unfoldr builds a stream from a seed value. The function takes the element and returns Nothing if it is done producing the stream or returns Just (a,b), in which case, a is the next Char in the string, and b is the seed value for further production. Properties
unstream . unfoldr f z = unfoldr f z
O(n) Like unfoldr, unfoldrNI builds a stream from a seed value. However, the length of the result is limited by the first argument to unfoldrNI. This function is more efficient than unfoldr when the length of the result is known. Properties
unstream (unfoldrNI n f z) = unfoldrN n f z
O(n) Like unfoldr, unfoldrN builds a stream from a seed value. However, the length of the result is limited by the first argument to unfoldrN. This function is more efficient than unfoldr when the length of the result is known.
O(n) Like unfoldr, unfoldrN builds a Text from a seed value. However, the length of the result should be limited by the first argument to unfoldrN. This function is more efficient than unfoldr when the maximum length of the result is known and correct, otherwise its performance is similar to unfoldr. Performs replacement on invalid scalar values.