Scoop API

scoop:scoop.core:0.1.0

src/lists.scoop

Selected production source · src/lists.scoop

1/**
2 * A finite iterable collection with a Long element count.
3 */
4public interface Collection<T> : Iterable<T> {
5 /**
6 * The number of elements currently in the collection.
7 */
8 public val size: Long
9}
11/**
12 * An ordered collection with zero-based Long indexing.
13 */
14public interface List<T> : Collection<T>, IndexGet<Long, T> {
15 /**
16 * Returns the element at a zero-based index; an index outside the list bounds is invalid.
17 */
18 public override operator fun get(index: Long): T
21/**
22 * An ordered collection supporting element replacement, insertion, removal, and clearing.
23 */
24public interface MutableList<T> : List<T>, IndexSet<Long, T> {
25 /**
26 * Replaces the element at an existing zero-based index without changing the size.
27 */
28 public override operator fun set(index: Long, value: T): Unit
29 /**
30 * Appends an element, or inserts it at the supplied position and shifts later elements.
31 */
32 public fun add(value: T): Unit
33 /**
34 * Appends an element, or inserts it at the supplied position and shifts later elements.
35 */
36 public fun add(index: Long, value: T): Unit
37 /**
38 * Removes and returns the element at the supplied index, shifting later elements toward the
39 * beginning.
40 */
41 public fun removeAt(index: Long): T
42 /**
43 * Removes every element from the list.
44 */
45 public fun clear(): Unit
48/**
49 * Copies the list in index order into an independent immutable array. Elements are shallow-copied;
50 * this is not a concurrent snapshot.
51 */
52public fun <T> List<T>.toArray(): Array<T> {
53 val count = size
54 return Array<T>(count) { index -> this[index] }
57/**
58 * Copies the list in index order into an independent mutable array. Later container mutations are
59 * independent.
60 */
61public fun <T> List<T>.toMutableArray(): MutableArray<T> {
62 val count = size
63 return MutableArray<T>(count) { index -> this[index] }