• Effekt Logo 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
      Example usage: examples/stdlib/array
      • Array [T]
      • A mutable 0-indexed fixed-sized array.
      • allocate [T] (size: Int): Array[T] / {}
      • Allocates a new array of size `size`, keeping its values _undefined_.
        Prefer using `array` constructor instead to ensure that values are defined.
      • fill [T] (arr: Array[T], filler: T): Unit / {}
      • Fills a given array in-place.
      • array [T] (size: Int, init: T): Array[T] / {}
      • Creates a new Array of size `size` filled with the value `init`
      • fromList [T] (list: List[T]): Array[T] / {}
      • Converts a List `list` to an Array
      • size [T] (arr: Array[T]): Int / {}
      • Gets the length of the array in constant time.
      • unsafeGet [T] (arr: Array[T], index: Int): T / {}
      • 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.
      • unsafeSet [T] (arr: Array[T], index: Int, value: T): Unit / {}
      • 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.
      • get [T] (arr: Array[T], index: Int): T / {Exception[OutOfBounds]}
      • Gets the element of the `arr` at given `index` in constant time,
        throwing an `Exception[OutOfBounds]` unless `0 ≤ index < arr.size`.
      • set [T] (arr: Array[T], index: Int, value: T): Unit / {Exception[OutOfBounds]}
      • Sets the element of the `arr` at given `index` to `value` in constant time,
        throwing an `Exception[OutOfBounds]` unless `0 ≤ index < arr.size`.
      • build [T] (size: Int) { index: (Int) => T }: Array[T] / {}
      • 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
      • resize [T] (source: Array[T], size: Int): Array[T] / {}
      • Resizes an array to a given size.
        
        O(N + M)
      • 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 the value at index i with that at index j.
        Warning: undefined behaviour if the indices are out bound.
        
        O(1)
      • swap [A] (arr: Array[A], i: Int, j: Int): Unit / {Exception[OutOfBounds]}
      • Swap the value at index i with that at index j.
        
        O(1)
      • toList [T] (arr: Array[T]): List[T] / {}
      • Converts the given array into a list.
        
        O(N)
      • foreach [T] (arr: Array[T]) { action: (T) => Unit }: Unit / {}
      • Traverse an array, applying the given action on every element.
        
        O(N)
      • foreach [T] (arr: Array[T]) { action: (T){Control} => Unit }: Unit / {}
      • Traverse an array, applying the given action on every element.
        
        O(N)
      • foreachIndex [T] (arr: Array[T]) { action: (Int, T) => Unit }: Unit / {}
      • Traverse an array, applying the given action on every element and its (zero-based) index.
        
        O(N)
      • foreachIndex [T] (arr: Array[T]) { action: (Int, T){Control} => Unit }: Unit / {}
      • Traverse an array, applying the given action on every element and its (zero-based) index.
        
        O(N)
      • sum (arr: Array[Int]): Int / {}
      • Sum the elements of the array.
        
        O(N)
      • equals [A] (this: Array[A], other: Array[A]) { eq: (A, A) => Bool }: Bool / {}
      • Checks whether two given arrays are equal with respect to an equalty funciton defined on their element.
        
        O(N)
      • map [A] (arr: Array[A]) { f: (A) => A }: Unit / {}
      • Map a function `f` over the elements in a given array.
        Modifies the array in-place.
        
        O(N)
      • mapped [A, B] (arr: Array[A]) { f: (A) => B }: Array[B] / {}
      • Map a function over elements.
        Allocates a new array of the same size.
        
        O(N)
      • reverse [A] (arr: Array[A]): Unit / {}
      • Reverses an array in-place.
        
        O(N)
      • reversed [A] (arr: Array[A]): Array[A] / {}
      • Creates a new array with elements in reverse order.
        
        O(N)
      • foldLeft [A, B] (arr: Array[A], init: B) { f: (B, A) => B }: B / {}
      • Fold an array using `f`, starting from the left given a starting value.
        
        O(N)
      • foldRight [A, B] (arr: Array[A], init: B) { f: (A, B) => B }: B / {}
      • Fold an array using `f`, starting from the right given a starting value.
        
        O(N)
      • filtered [A] (arr: Array[A]) { shouldKeep: (A) => Bool }: Array[A] / {}
      • 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)
      • all [A] (arr: Array[A]) { predicate: (A) => Bool }: Bool / {}
      • Check if predicate is true for all elements.
        
        O(N)
      • any [A] (arr: Array[A]) { predicate: (A) => Bool }: Bool / {}
      • Check if predicate is true for at least one element.
        
        O(N)
      • count [A] (arr: Array[A]) { predicate: (A) => Bool }: Int / {}
      • Count elements satisfying the predicate.
        
        O(N)
      • take [A] (arr: Array[A], n: Int): Array[A] / {}
      • Take first n elements.
        Returns a new array.
        
        O(N)
      • drop [A] (arr: Array[A], n: Int): Array[A] / {}
      • Returns a new array.
        
        O(N)
      • sliced [A] (arr: Array[A], start: Int, end: Int): Array[A] / {}
      • Return a slice from start (inclusive) to end (exclusive).
        Returns a new array.
        
        O(N)
      • zipped [A, B] (this: Array[A], other: Array[B]): Array[Tuple2[A, B]] / {}
      • Zip two arrays into an array of pairs.
        Length is minimum of input lengths.
        
        O(min(N, M))
      • zippedWith [A, B, C] (this: Array[A], other: Array[B]) { f: (A, B) => C }: Array[C] / {}
      • Combine two arrays using given function.
        Length is minimum of input lengths.
        
        O(min(N, M))
      • unzipped [A, B] (arr: Array[Tuple2[A, B]]): Tuple2[Array[A], Array[B]] / {}
      • Produce a pair of arrays from an array of pairs.
        Allocates two new arrays as a result.
        
        O(N)
      • partioned [A] (arr: Array[A]) { pred: (A) => Bool }: Tuple2[Array[A], Array[A]] / {}
      • 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)
      • indexOf [A] (arr: Array[A], toFind: A) { eq: (A, A) => Bool }: Option[Int] / {}
      • Get the _first_ index of the last occurance of `elem`, if there is any.
        
        O(N)
      • lastIndexOf [A] (arr: Array[A], toFind: A) { eq: (A, A) => Bool }: Option[Int] / {}
      • Get the _last_ index of the last occurance of `elem`, if there is any.
        
        O(N)
      • binarySearch [A] (arr: Array[A], toFind: A) { ord: (A, A) => Ordering }: Option[Int] / {}
      • Perform binary search to find the index of a given element.
        
        O(log N)
      • sort [A] (arr: Array[A]) { ord: (A, A) => Ordering }: Unit / {}
      • 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
      • sorted [A] (arr: Array[A]) { ord: (A, A) => Ordering }: Array[A] / {}
      • 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
      • 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 / {}