Should mutableSublist not be required to support mutation operations for changing size? #402
AlexKnauth
started this conversation in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
What should the
mutableSublist
method on mutable lists produce?If the hierarchy of list interfaces looks something like this:
ReadableList
reading operations: elements, unmodifiable sublistsList
functional operations including changing sizeMutableList
mutation operations including changing sizeThen it seems like any mutable list implementation would have to have to make
mutableSublist
produce aMutableList
that supports mutation operations that can change the size, such as appending, prepending, inserting, and removing.But for many mutable list implementations, it wouldn't make sense to do this. Instead, it might make more sense for their
mutableSublist
to produce a "slice", like Rust's&mut [T]
, that does not support operations that can change the size.So should a new interface be inserted between
MutableList
andReadableList
which doesn't support those operations that can change the size?ReadableList
reading operations: elements, unmodifiable sublistsList
functional operations including changing sizeIndexMutableList
mutation operations by existing index only, NO changing sizeMutableList
mutation operations including changing sizeReadableList
methodsublist
producesReadableList
:and can produce
List
if desired.ReadableList
,and should NOT produce
IndexMutableList
orMutableList
.IndexMutableList
methodmutableSublist
producesIndexMutableList
:IndexMutableList
,but does not have to implement
MutableList
.Fixed-length mutable lists such as Racket's
vector
should implementIndexMutableList
but notMutableList
.Flexible-length mutable lists such as Racket's
gvector
should implementMutableList
.I expect most mutable list implementations will choose to make
mutableSublist
produce onlyIndexMutableList
, notMutableList
.There's nothing stopping a mutable list implementation that wants to override
mutableSublist
to produce aMutableList
with the "appending to the sublist inserts into the middle of the backing list" behavior, but this way it wouldn't be mandatory.Beta Was this translation helpful? Give feedback.
All reactions