Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Utility for construction of vectors when the size is not known ahead.
Synopsis
- data Accumulator a
- init :: Accumulator a
- add :: a -> Accumulator a -> Accumulator a
- addList :: [a] -> Accumulator a -> Accumulator a
- addFoldable :: Foldable f => f a -> Accumulator a -> Accumulator a
- toVector :: Vector v a => Accumulator a -> v a
- toReverseVector :: Vector v a => Accumulator a -> v a
Documentation
data Accumulator a Source #
Constructor of vectors optimised for appending elements one by one, providing for \(\mathcal{O}(n)\) complexity of the whole construction process.
Very useful as accumulator in folds.
Under the hood it is the size counter and a reverse list of elements. When executed, a vector of the according size gets allocated and gets populated with the elements in reverse order (starting from the last element).
init :: Accumulator a Source #
Create an empty accumulator.
add :: a -> Accumulator a -> Accumulator a Source #
Add an element to the accumulator.
addList :: [a] -> Accumulator a -> Accumulator a Source #
Add a list of elements to the accumulator.
addFoldable :: Foldable f => f a -> Accumulator a -> Accumulator a Source #
Add a foldable of elements to the accumulator.
Execution
toVector :: Vector v a => Accumulator a -> v a Source #
Finalise the accumulator as vector.
toReverseVector :: Vector v a => Accumulator a -> v a Source #
Finalise the accumulator as vector in reverse order.