An array-backed immutable sequence would natively support random access Natural -> Maybe a and would be very fast indeed, provided it could be made safe such that the array was fully encapsulated by the data type. This would mean that no public construction patterns should allow wrapping of an array: arrays should be fully existentialized behind a series of exported minimal interactions. As an example:
public static Vector<A> create(Consumer<Consumer<A>> withAdd) {
// ...
}
This interface would receive a Consumer that would itself receive a Consumer representing an add invocation, so a valid argument might do something like:
Vector<Integer> ints = create(add -> {
add.accept(1);
add.accept(2);
add.accept(3);
});
Each add would result in the internal array being updated, and after withAdd was finished, some flag would be flipped to specify the array is no longer candidate for update, so if someone did something accidental and caustic, like leaked add into an atomic reference, add could not be used after initialization to violate the immutable properties of the Vector.
This data type would likely be eventually supplanted by a BAMT, so it may or may not be worth adding in the short term.
An array-backed immutable sequence would natively support random access
Natural -> Maybe aand would be very fast indeed, provided it could be made safe such that the array was fully encapsulated by the data type. This would mean that no public construction patterns should allow wrapping of an array: arrays should be fully existentialized behind a series of exported minimal interactions. As an example:This interface would receive a
Consumerthat would itself receive aConsumerrepresenting anaddinvocation, so a valid argument might do something like:Each
addwould result in the internal array being updated, and afterwithAddwas finished, some flag would be flipped to specify the array is no longer candidate for update, so if someone did something accidental and caustic, like leakedaddinto an atomic reference,addcould not be used after initialization to violate the immutable properties of theVector.This data type would likely be eventually supplanted by a BAMT, so it may or may not be worth adding in the short term.