eof package:streamly-core
Succeeds if we are at the end of input, fails otherwise.
>>> Stream.parse ((,) <$> Parser.satisfy (> 0) <*> Parser.eof) $ Stream.fromList [1]
Right (1,())
createOf n folds a maximum of
n elements from the
input stream to an
Array.
createOfLast n folds a maximum of
n elements from
the end of the input stream to an
Array.
Get the size. Size cannot be zero, should be at least 1 byte.
createOf n folds a maximum of
n elements from the
input stream to an
MutArray.
The array capacity is guranteed to be at least
n.
>>> createOf = MutArray.createWithOf MutArray.emptyOf
>>> createOf n = Fold.take n (MutArray.unsafeCreateOf n)
>>> createOf n = MutArray.appendMax n MutArray.empty
createOf n folds a maximum of
n elements from the
input stream to an
Array.
>>> createOf n = Fold.take n (MutArray.unsafeCreateOf n)
Pre-release
See performance notes in
oneOf.
>>> noneOf xs = Parser.satisfy (`Foldable.notElem` xs)
Match any one of the elements in the supplied list.
>>> oneOf xs = Parser.satisfy (`Foldable.elem` xs)
When performance matters a pattern matching predicate could be more
efficient than a
Foldable datatype:
let p x =
case x of
a -> True
e -> True
_ -> False
in satisfy p
GHC may use a binary search instead of linear search in the list.
Alternatively, you can also use an array instead of list for storage
and search.
createOfLast n returns the last n elements of the stream in a
ring array. n must be non-zero.
Returns
True if all the elements of the first stream occur, in
order, in the second stream. The elements do not have to occur
consecutively. A stream is a subsequence of itself.
>>> Stream.isSubsequenceOf (Stream.fromList "hlo") (Stream.fromList "hello" :: Stream IO Char)
True
Like
createOf but creates a pinned array.
Deprecated: Please use createOf' instead.
Like
createOf but does not check the array bounds when writing.
The fold driver must not call the step function more than
n
times otherwise it will corrupt the memory and crash. This function
exists mainly because any conditional in the step function blocks
fusion causing 10x performance slowdown.
Deprecated: Please use unsafeCreateOf' instead.
O(1) Slice an array in constant time.
Caution: The bounds of the slice are not checked.
Unsafe
Pre-release
Like
createOf but creates a pinned array.
createOfLast n folds a maximum of
n elements from
the end of the input stream to an
MutArray.
Deprecated: Please use createWithOf instead.
Deprecated: Please use createOf' instead.
Like
createOf but writes the array in reverse order.
Pre-release
O(1) Get a reference to a slice from a mutable array. Throws an
error if the slice extends out of the array bounds.
The capacity of the slice is the same as its length i.e. it does not
have any unused or reserved space at the end.
The slice shares the same underlying mutable array when created.
However, if the slice or the original array is reallocated by growing
or shrinking then it will be copied to new memory and they will no
longer share the same memory.
Pre-release