Walan kulu #
Walan
represents List
class in Mosc and extends
Tugun class. It’s An indexable contiguous collection of elements. More details
here.
Static Methods #
kura() #
Creates a new empty list. Equivalent to [].
lafaa(size, element) #
Creates a new list with size
elements, all set to element
.
It is a runtime error if size
is not a non-negative integer.
Methods #
aBeeFaraAkan(other) #
Appends each element of other
in the same order to the end of the list. other
must be an iterable.
nin walan = [0, 1, 2, 3, 4]
walan.aBeeFaraAkan([5, 6])
A.yira(walan) # > [0, 1, 2, 3, 4, 5, 6]
Returns the added items.
aFaraAkan(item) #
Appends item
to the end of the list. Returns the added item.
diossi() #
Removes all elements from the list.
hakan #
The number of elements in the list.
aDayoro(value) #
Returns the index of value
in the list, if found. If not found, returns -1.
nin wala = [0, 1, 2, 3, 4]
A.yira(wala.aDayoro(3)) # > 3
A.yira(wala.aDayoro(20)) # > -1
aBoOyorola(index) #
Removes the element at index
. If index
is negative, it counts backwards from the end of the list where -1
is the last element. All trailing elements are shifted up to fill in where the removed element was.
nin walan = ["a", "b", "c", "d"]
walan.aBoOyorola(1)
A.yira(walan) # > [a, c, d]
Returns the removed item.
A.yira(["a", "b", "c"].aBoOyorola(1)) # > b
It is a runtime error if the index is not an integer or is out of bounds.
aBoye(value) #
Removes the first value found in the list that matches the given value
, using regular equality to compare them. All trailing elements are shifted up to fill in where the removed element was.
nin walan = ["a", "b", "c", "d"]
walan.aBoye("b")
A.yira(walan) # > [a, c, d]
Returns the removed value, if found. If the value is not found in the list, returns gansan
.
A.yira(["a", "b", "c"].aBoye("b")) # > b
A.yira(["a", "b", "c"].aBoye("not found")) # > gansan
aDon(index, item) #
Inserts the item
at index
in the list.
nin walan = ["a", "b", "c", "d"]
walan.aDon(1, "e")
A.yira(walan) # > [a, e, b, c, d]
The index
may be one past the last index in the list to append an element.
nin walan = ["a", "b", "c"]
walan.aDon(3, "d")
A.yira(walan) # > [a, b, c, d]
If index
is negative, it counts backwards from the end of the list. It bases this on the length of the list after inserted the element, so that -1
will append the element, not insert it before the last element.
nin walan = ["a", "b"]
walan.aDon(-1, "d")
walan.aDon(-2, "c")
A.yira(walan) # > [a, b, c, d]
Returns the inserted item.
A.yira(["a", "c"].aDon(1, "b")) # > b
It is a runtime error if the index
is not an integer or is out of bounds.
iterate(iterator), iteratorValue(iterator) #
Implements the iterator protocol for iterating over the elements in the list.
falen(index0, index1) #
Swaps values inside the list around. Puts the value from index0
in index1
, and the value from index1
at index0
in the list.
nin walan = [0, 1, 2, 3, 4]
walan.falen(0, 3)
A.yira(walan) # > [3, 1, 2, 0, 4]
woloma(), woloma(comparator) #
Sorts the elements of a list in-place; altering the list. The default sort is implemented using the quicksort algorithm.
nin walan = [4, 1, 3, 2].woloma()
A.yira(walan) # > [1, 2, 3, 4]
A comparison function comparer
can be provided to customise the element sorting. The comparison function must return a boolean value specifying the order in which elements should appear in the list.
The comparison function accepts two arguments a
and b
, two values to compare, and must return a boolean indicating the inequality between the arguments. If the function returns true, the first argument a will appear before the second b in the sorted results.
A compare function like {(a, b) => true }
will always put a before b. The default compare function is {(a, b) => a < b }
.
nin walan = [9, 6, 8, 7]
walan.woloma {(a, b) => a < b}
A.yira(walan) # > [6, 7, 8, 9]
It is a runtime error if comparer
is not a function.
[index] operator #
Gets the element at index
. If index
is negative, it counts backwards from the end of the list where -1
is the last element.
nin walan = ["a", "b", "c"]
A.yira(walan[1]) # > b
If index is a Range, a new list is populated from the elements in the range.
nin walan = ["a", "b", "c"]
A.yira(walan[0..1]) # > [a, b]
You can use walan[0..-1]
to shallow-copy a list.
It is a runtime error if the index is not an integer or range, or is out of bounds.
[index]=(item) operator #
Replaces the element at index
with item
. If index
is negative, it counts backwards from the end of the list where -1
is the last element.
nin walan = ["a", "b", "c"]
walan[1] = "new"
A.yira(walan) # > [a, new, c]
It is a runtime error if the index is not an integer or is out of bounds.
+(other) operator #
Appends a list to the end of the list (concatenation). other must be an iterable.
nin letters = ["a", "b", "c"]
nin other = ["d", "e", "f"]
nin combined = letters + other
A.yira(combined) # > [a, b, c, d, e, f]
*(count) operator #
Creates a new list by repeating this one count
times. It is a runtime error if count
is not a non-negative integer.
nin digits = [1, 2]
nin tripleDigits = digits * 3
A.yira(tripleDigits) # > [1, 2, 1, 2, 1, 2]