Definitions on Arrays #
This file contains various definitions on Array. It does not contain
proofs about these definitions, those are contained in other files in Batteries.Data.Array.
Check whether xs and ys are equal as sets, i.e. they contain the same
elements when disregarding order and duplicates. O(n*m)! If your element type
has an Ord instance, it is asymptotically more efficient to sort the two
arrays, remove duplicates and then compare them elementwise.
Equations
Instances For
Returns the first minimal element among d and elements of the array.
If start and stop are given, only the subarray xs[start:stop] is
considered (in addition to d).
Equations
Instances For
Find the first minimal element of an array. If the array is empty, d is
returned. If start and stop are given, only the subarray xs[start:stop] is
considered.
Equations
Instances For
Find the first minimal element of an array. If the array is empty, none is
returned. If start and stop are given, only the subarray xs[start:stop] is
considered.
Equations
Instances For
Find the first minimal element of an array. If the array is empty, default is
returned. If start and stop are given, only the subarray xs[start:stop] is
considered.
Equations
Instances For
Returns the first maximal element among d and elements of the array.
If start and stop are given, only the subarray xs[start:stop] is
considered (in addition to d).
Equations
Instances For
Find the first maximal element of an array. If the array is empty, d is
returned. If start and stop are given, only the subarray xs[start:stop] is
considered.
Equations
Instances For
Find the first maximal element of an array. If the array is empty, none is
returned. If start and stop are given, only the subarray xs[start:stop] is
considered.
Equations
Instances For
Find the first maximal element of an array. If the array is empty, default is
returned. If start and stop are given, only the subarray xs[start:stop] is
considered.
Equations
Instances For
Folds a monadic function over an array from the left, accumulating the partial results starting with
init. The accumulated value is combined with the each element of the list in order, using f.
The optional parameters start and stop control the region of the array to be folded. Folding
proceeds from start (inclusive) to stop (exclusive), so no folding occurs unless start < stop.
By default, the entire array is folded.
Examples:
example [Monad m] (f : α → β → m α) :
Array.scanlM f x₀ #[a, b, c] = (do
let x₁ ← f x₀ a
let x₂ ← f x₁ b
let x₃ ← f x₂ c
pure #[x₀, x₁, x₂, x₃])
:= by simp [scanlM, scanlM.loop]
example [Monad m] (f : α → β → m α) :
Array.scanlM f x₀ #[a, b, c] (start := 1) (stop := 3) = (do
let x₁ ← f x₀ b
let x₂ ← f x₁ c
pure #[x₀, x₁, x₂])
:= by simp [scanlM, scanlM.loop]
Equations
Instances For
Folds a monadic function over an array from the right, accumulating the partial results starting
with init. The accumulated value is combined with the each element of the list in order using f.
The optional parameters start and stop control the region of the array to be folded. Folding
proceeds from start (exclusive) to stop (inclusive), so no folding occurs unless start > stop.
By default, the entire array is folded.
Examples:
example [Monad m] (f : α → β → m β) :
Array.scanrM f x₀ #[a, b, c] = (do
let x₁ ← f c x₀
let x₂ ← f b x₁
let x₃ ← f a x₂
pure #[x₃, x₂, x₁, x₀])
:= by simp [scanrM, scanrM.loop]
example [Monad m] (f : α → β → m β) :
Array.scanrM f x₀ #[a, b, c] (start := 3) (stop := 1) = (do
let x₁ ← f c x₀
let x₂ ← f b x₁
pure #[x₂, x₁, x₀])
:= by simp [scanrM, scanrM.loop]
Equations
Instances For
Fold a function f over the array from the left, returning the array of partial results.
scanl (· + ·) 0 #[1, 2, 3] = #[0, 1, 3, 6]
Equations
Instances For
Fold a function f over the array from the right, returning the array of partial results.
scanr (· + ·) 0 #[1, 2, 3] = #[6, 5, 3, 0]
Equations
Instances For
Check whether a subarray is empty.