Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Safe, array-backed RandomAccess Sequence #31

Open
jnape opened this issue Jan 14, 2022 · 0 comments
Open

Safe, array-backed RandomAccess Sequence #31

jnape opened this issue Jan 14, 2022 · 0 comments

Comments

@jnape
Copy link
Member

jnape commented Jan 14, 2022

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant