This is the standard library of Droid.
Stream object - contains methods that work on iterable containers.
get[T](iterator: Function[Void, T?]): Stream[T]
- wraps an iterator into a stream.
contains[T](iterable: Stream[T], value: T): Bool where T: Equality
- returns true if the element equals any element. O(n).
find[T](iterable: Stream[T], predicate: T -> Bool, from: Int?): Int?
- returns the first element (after or at index from
, default 0) for which the predicate
returns true. Returns None
if there is no such element. O(n).
any[T](iterable: Stream[T], predicate: T -> Bool): Bool
- returns true
if the predicate returns true for any element. Returns false
if there are no elements. O(n).
all[T](iterable: Stream[T], predicate: T -> Bool): Bool
- returns true
if the predicate returns true for all the elements. Returns true
if there are no elements. O(n).
filter[T](iterable: Stream[T], predicate: T -> Bool): Bool
- returns a new stream with only the elements for which the predicate
returns true
. O(n).
map[T, R](iterable: Stream[T], function: T -> R): Stream[R]
- returns a new stream where each element is replaced by the result of applying the function
to it. O(n).
foldLeft[T, R](iterable: Stream[T], first: R, function: (T, R) -> R): R
- see Folds . O(n).
foldRight[T, R](iterable: Stream[T], first: R, function: (T, R) -> R): R
- see Folds . O(n).
Stream[T] interface - specifies that the elements in this container can be iterated over.
getIterator(): Function[Void, T?]
- returns an iterator for the elements in a container. The iterator returns the next element when called, or None
if there are no more elements.
Array object - contains methods that work on arrays.
get[T](elements: Stream[T]?): Array[T]
- returns a new array of all the elements
. O(n).
generate[T](count: Int, function: Int -> T): Array[T]
- returns a new array as [function(0), function(1), ..., function(count - 1)]
. O(n).
Array[T] : Stream[T] class - a mutable container whose elements occupy a contiguous area of the memory.
get(index: Int): T
- returns the element at position index
(the first element is positioned at element 0). O(1). Throws IndexException
if index < 0
or index >= Size
set(index: Int, value: T)
- replaces the element at position index
(the first element is positioned at element 0). O(1).
getSize(): Int
- returns the number of elements in the array. O(1).
sort(before: (T, T) -> Bool, stable: Bool?)
- sorts the array so that any element a
comes before b
if before(a, b)
. If stable
is true
(default false
), it ensures that any two elements are only swapped if required. It is in-place. O(n log n).
push(value: T)
- appends an element to the end. O(1)*.
pop()
- removes the last element. O(1). Throws IndexException
if there are no elements.
getLast(): T
- returns the last element. O(1). Throws IndexException
if there are no elements.
clear()
- removes all the elements. O(1).
swap(first: Int, last: Int)
- swaps two elements. O(1). Throws IndexException
if any of the indexes are out of bounds (0 to Size - 1).
concatenate(other: Array[T]): Array[T]
- returns a new array whose elements are the concatenation of this array and the other
array. O(n).
getIterator(): Function[Void, T?]
- returns a stream that iterates over the elements.
List object - contains methods that work on arrays.
get[T](elements: Stream[T]?): List[T]
- returns a new list of all the elements
. O(n).
List[T] : Stream[T] class - an immutable container whose elements are linked together.
get(index: Int): T
- returns the element at position index
. O(n). Throws IndexException
if not 0 <= index < Size
.
getFirst(): T
- returns the first element. O(1). Throws IndexException
if there are no elements.
getLast(): T
- returns the last element. O(1). Throws IndexException
if there are no elements.
getFront(): List[T]
- returns all elements but the last. O(1). Throws IndexException
if there are no elements.
getBack(): List[T]
- returns all elements but the first. O(1). Throws IndexException
if there are no elements.
getSize(): Int
- returns the number of elements in the list. O(1).
concatenate(other: List[T]): List[T]
- returns a new list whose elements are the concatenation of this list and the other
list. O(n).
sort(before: (T, T) -> Bool): List[T]
- returns a new list with the same elements sorted so that any element a
comes before b
if before(a, b)
. It is stable, meaning that any two elements are only swapped if required. O(n log n).
getIterator(): Function[Void, T?]
- returns a stream that iterates over the elements.
* amortized