-
Effekt Library
- array
- Array
- allocate
- fill
- array
- fromList
- size
- unsafeGet
- unsafeSet
- get
- set
- build
- resize
- copy
- copy
- unsafeSwap
- swap
- toList
- foreach
- foreach
- foreachIndex
- foreachIndex
- sum
- equals
- map
- mapped
- reverse
- reversed
- foldLeft
- foldRight
- filtered
- all
- any
- count
- take
- drop
- sliced
- zipped
- zippedWith
- unzipped
- partioned
- indexOf
- lastIndexOf
- binarySearch
- sort
- sorted
- show
- show
- show
- show
- show
- println
- println
- println
- println
- array Jump to source: libraries/common/array.effekt
- Array
[T]
- allocate
[T] (size: Int): Array[T] / {}
- fill
[T] (arr: Array[T], filler: T): Unit / {}
- array
[T] (size: Int, init: T): Array[T] / {}
- fromList
[T] (list: List[T]): Array[T] / {}
- size
[T] (arr: Array[T]): Int / {}
- unsafeGet
[T] (arr: Array[T], index: Int): T / {}
- unsafeSet
[T] (arr: Array[T], index: Int, value: T): Unit / {}
- get
[T] (arr: Array[T], index: Int): T / {Exception[OutOfBounds]}
- set
[T] (arr: Array[T], index: Int, value: T): Unit / {Exception[OutOfBounds]}
- build
[T] (size: Int) { index: (Int) => T }: Array[T] / {}
- resize
[T] (source: Array[T], size: Int): Array[T] / {}
- copy
[T] (array: Array[T]): Array[T] / {}
- copy
[T] (from: Array[T], start: Int, to: Array[T], offset: Int, length: Int): Unit / {Exception[OutOfBounds]}
- unsafeSwap
[A] (arr: Array[A], i: Int, j: Int): Unit / {}
- swap
[A] (arr: Array[A], i: Int, j: Int): Unit / {Exception[OutOfBounds]}
- toList
[T] (arr: Array[T]): List[T] / {}
- foreach
[T] (arr: Array[T]) { action: (T) => Unit }: Unit / {}
- foreach
[T] (arr: Array[T]) { action: (T){Control} => Unit }: Unit / {}
- foreachIndex
[T] (arr: Array[T]) { action: (Int, T) => Unit }: Unit / {}
- foreachIndex
[T] (arr: Array[T]) { action: (Int, T){Control} => Unit }: Unit / {}
- sum
(arr: Array[Int]): Int / {}
- equals
[A] (this: Array[A], other: Array[A]) { eq: (A, A) => Bool }: Bool / {}
- map
[A] (arr: Array[A]) { f: (A) => A }: Unit / {}
- mapped
[A, B] (arr: Array[A]) { f: (A) => B }: Array[B] / {}
- reverse
[A] (arr: Array[A]): Unit / {}
- reversed
[A] (arr: Array[A]): Array[A] / {}
- foldLeft
[A, B] (arr: Array[A], init: B) { f: (B, A) => B }: B / {}
- foldRight
[A, B] (arr: Array[A], init: B) { f: (A, B) => B }: B / {}
- filtered
[A] (arr: Array[A]) { shouldKeep: (A) => Bool }: Array[A] / {}
- all
[A] (arr: Array[A]) { predicate: (A) => Bool }: Bool / {}
- any
[A] (arr: Array[A]) { predicate: (A) => Bool }: Bool / {}
- count
[A] (arr: Array[A]) { predicate: (A) => Bool }: Int / {}
- take
[A] (arr: Array[A], n: Int): Array[A] / {}
- drop
[A] (arr: Array[A], n: Int): Array[A] / {}
- sliced
[A] (arr: Array[A], start: Int, end: Int): Array[A] / {}
- zipped
[A, B] (this: Array[A], other: Array[B]): Array[Tuple2[A, B]] / {}
- zippedWith
[A, B, C] (this: Array[A], other: Array[B]) { f: (A, B) => C }: Array[C] / {}
- unzipped
[A, B] (arr: Array[Tuple2[A, B]]): Tuple2[Array[A], Array[B]] / {}
- partioned
[A] (arr: Array[A]) { pred: (A) => Bool }: Tuple2[Array[A], Array[A]] / {}
- indexOf
[A] (arr: Array[A], toFind: A) { eq: (A, A) => Bool }: Option[Int] / {}
- lastIndexOf
[A] (arr: Array[A], toFind: A) { eq: (A, A) => Bool }: Option[Int] / {}
- binarySearch
[A] (arr: Array[A], toFind: A) { ord: (A, A) => Ordering }: Option[Int] / {}
- sort
[A] (arr: Array[A]) { ord: (A, A) => Ordering }: Unit / {}
- sorted
[A] (arr: Array[A]) { ord: (A, A) => Ordering }: Array[A] / {}
- show
[A] (arr: Array[A]) { showA: (A) => String }: String / {}
- show
(l: Array[Int]): String / {}
- show
(l: Array[Double]): String / {}
- show
(l: Array[Bool]): String / {}
- show
(l: Array[String]): String / {}
- println
(l: Array[Int]): Unit / {}
- println
(l: Array[Double]): Unit / {}
- println
(l: Array[Bool]): Unit / {}
- println
(l: Array[String]): Unit / {}
Example usage: examples/stdlib/array
A mutable 0-indexed fixed-sized array.
Allocates a new array of size `size`, keeping its values _undefined_. Prefer using `array` constructor instead to ensure that values are defined.
Fills a given array in-place.
Creates a new Array of size `size` filled with the value `init`
Converts a List `list` to an Array
Gets the length of the array in constant time.
Gets the element of the `arr` at given `index` in constant time. Unchecked Precondition: `index` is in bounds (0 ≤ index < arr.size) Prefer using `get` instead.
Sets the element of the `arr` at given `index` to `value` in constant time. Unchecked Precondition: `index` is in bounds (0 ≤ index < arr.size) Prefer using `set` instead.
Gets the element of the `arr` at given `index` in constant time, throwing an `Exception[OutOfBounds]` unless `0 ≤ index < arr.size`.
Sets the element of the `arr` at given `index` to `value` in constant time, throwing an `Exception[OutOfBounds]` unless `0 ≤ index < arr.size`.
Builds a new Array of size `size` from a computation `index` which gets an index and returns a value that will be on that position in the resulting array
Resizes an array to a given size. O(N + M)
Swap the value at index i with that at index j. Warning: undefined behaviour if the indices are out bound. O(1)
Swap the value at index i with that at index j. O(1)
Converts the given array into a list. O(N)
Traverse an array, applying the given action on every element. O(N)
Traverse an array, applying the given action on every element. O(N)
Traverse an array, applying the given action on every element and its (zero-based) index. O(N)
Traverse an array, applying the given action on every element and its (zero-based) index. O(N)
Sum the elements of the array. O(N)
Checks whether two given arrays are equal with respect to an equalty funciton defined on their element. O(N)
Map a function `f` over the elements in a given array. Modifies the array in-place. O(N)
Map a function over elements. Allocates a new array of the same size. O(N)
Reverses an array in-place. O(N)
Creates a new array with elements in reverse order. O(N)
Fold an array using `f`, starting from the left given a starting value. O(N)
Fold an array using `f`, starting from the right given a starting value. O(N)
Filters a given array with respect to a given predicate such that a new array containing all the elements for which the predicate holds is allocated. O(N)
Check if predicate is true for all elements. O(N)
Check if predicate is true for at least one element. O(N)
Count elements satisfying the predicate. O(N)
Take first n elements. Returns a new array. O(N)
Returns a new array. O(N)
Return a slice from start (inclusive) to end (exclusive). Returns a new array. O(N)
Zip two arrays into an array of pairs. Length is minimum of input lengths. O(min(N, M))
Combine two arrays using given function. Length is minimum of input lengths. O(min(N, M))
Produce a pair of arrays from an array of pairs. Allocates two new arrays as a result. O(N)
Partition a given array into two arrays. The left array contains the elements that satsify the predicate, the right array contains the elements that do not. O(N)
Get the _first_ index of the last occurance of `elem`, if there is any. O(N)
Get the _last_ index of the last occurance of `elem`, if there is any. O(N)
Perform binary search to find the index of a given element. O(log N)
Sort an array in-place using provided comparison function. Note: sort is unstable since it uses QuickSort (unlike list::sortBy) O(N log N) average case
Sort an array using provided comparison function. A newly allocated sorted array is returned as result, i.e., the sorting is not in-place. Note: sort is unstable since it uses QuickSort (unlike list::sortBy) O(N log N) average case