March Docs

Range

Range module: integer ranges as first-class values.

A range is a record %{start: Int, stop: Int, step: Int}. Ranges are half-open: [start, stop) when step > 0, (stop, start] when step < 0. step must be non-zero; new/1 defaults to step = 1.

Functions

fnnewnew(start : Int, stop : Int) : %{start: Int, stop: Int, step: Int}#

Creates a range [start, stop) with step 1.

fnnew_stepnew_step(start : Int, stop : Int, step : Int) : %{start: Int, stop: Int, step: Int}#

Creates a range with an explicit step. Step must be non-zero.

fnto_listto_list(r : %{start: Int, stop: Int, step: Int}) : List(Int)#

Converts the range to a list of integers.

fncontainscontains(r : %{start: Int, stop: Int, step: Int}, n : Int) : Bool#

Returns true if n is within the range.

fnsizesize(r : %{start: Int, stop: Int, step: Int}) : Int#

Returns the number of elements in the range.

fnis_emptyis_empty(r : %{start: Int, stop: Int, step: Int}) : Bool#

Returns true if the range contains no elements.

fnmapmap(r : %{start: Int, stop: Int, step: Int}, f : Int -> b) : List(b)#

Applies f to each element, returning a list of results.

fnfilterfilter(r : %{start: Int, stop: Int, step: Int}, f : Int -> Bool) : List(Int)#

Returns a list of elements satisfying predicate f.

fneacheach(r : %{start: Int, stop: Int, step: Int}, f : Int -> Unit) : Unit#

Calls f for each element in the range (for side effects).

fnreducereduce(r : %{start: Int, stop: Int, step: Int}, acc : b, f : (b, Int) -> b) : b#

Folds over the range: f(acc, element) -> acc.

fnreversereverse(r : %{start: Int, stop: Int, step: Int}) : %{start: Int, stop: Int, step: Int}#

Returns a new range iterating in the opposite direction.

fnfirstfirst(r : %{start: Int, stop: Int, step: Int}) : Option(Int)#

Returns Some of the first element, or None if empty.

fnlastlast(r : %{start: Int, stop: Int, step: Int}) : Option(Int)#

Returns Some of the last element, or None if empty.

fnallall(r : %{start: Int, stop: Int, step: Int}, f : Int -> Bool) : Bool#

Returns true if all elements satisfy f.

fnanyany(r : %{start: Int, stop: Int, step: Int}, f : Int -> Bool) : Bool#

Returns true if any element satisfies f.

fnsumsum(r : %{start: Int, stop: Int, step: Int}) : Int#

Returns the sum of all elements in the range.