Array.Builder

The functions in this module allows you to build an Array more efficiently. Unless you have a performance problem, it's recommended to stick with the functions in the Array module.

type Builder a

A Builder represents an Array under construction. The functionality of this type is intentionally limited. You can only create it, add elements to it and convert it to an Array. Any other operation is out of scope. In return, you get a faster way of building Arrays.

empty : Int -> Builder a

Creates a Builder without any elements.

The Int argument lets you specify the amount of elements you expect to end up in the final Array. Nothing bad happens if you pass a wrong value, but being exact gives you a tiny bit more performance.

In other words: it's ok to pass 0.

fromArray : Array a -> Builder a

Creates a Builder based on an existing Array.

pushLast : a -> Builder a -> Builder a

Add a single element to a Builder.

append : Array a -> Builder a -> Builder a

Adds the elements of an Array to the end of a Builder.

toArray : Builder a -> Array a

Converts a Builder to an Array.