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
*/4
public interface Collection<T> : Iterable<T> {5
/**6
* The number of elements currently in the collection.7
*/8
public val size: Long9
}11
/**12
* An ordered collection with zero-based Long indexing.13
*/14
public 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): T19
}21
/**22
* An ordered collection supporting element replacement, insertion, removal, and clearing.23
*/24
public 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): Unit29
/**30
* Appends an element, or inserts it at the supplied position and shifts later elements.31
*/32
public fun add(value: T): Unit33
/**34
* Appends an element, or inserts it at the supplied position and shifts later elements.35
*/36
public fun add(index: Long, value: T): Unit37
/**38
* Removes and returns the element at the supplied index, shifting later elements toward the39
* beginning.40
*/41
public fun removeAt(index: Long): T42
/**43
* Removes every element from the list.44
*/45
public fun clear(): Unit46
}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
*/52
public fun <T> List<T>.toArray(): Array<T> {53
val count = size54
return Array<T>(count) { index -> this[index] }55
}57
/**58
* Copies the list in index order into an independent mutable array. Later container mutations are59
* independent.60
*/61
public fun <T> List<T>.toMutableArray(): MutableArray<T> {62
val count = size63
return MutableArray<T>(count) { index -> this[index] }64
}