2015 003e Vector

John Reppy edited this page Sep 2, 2015 · 1 revision
structure Vector : VECTOR

We propose three new functions for the Vector module.

This page is part of proposal 2015-003.


Synopsis

val toList  : 'a vector -> 'a list

val append  : 'a vector * 'a -> 'a vector
val prepend : 'a * 'a vector -> 'a vector

Description

  • toList vec

returns the list of the elements of the vector `vec`. Will raise the `Size` exception if the resulting vector would exceed `maxLen` elements.
  • append (vec, x)

returns the vector formed by adding the element `x` to the end of the vector `vec`. Will raise the `Size` exception if the resulting vector would exceed `maxLen` elements.
  • prepend (x, vec)

returns the vector formed by adding the element `x` to the beginning of the vector `vec`. Will raise the `Size` exception if the resulting vector would exceed `maxLen` elements.

Rationale

The toList operation complements the existing fromList and can be implemented more efficiently than by using List.tabulate. Adding it helps reduce the friction of converting between the different sequence types.

The append and prepend operations provide a convinent (and slightly more efficient) way to grow a vector by one element, although they are still O(n) operations.

You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.