Elixir v1.6.5 Range View Source

Defines a range.

A range represents a discrete number of values where the first and last values are integers.

Ranges can be either increasing (first <= last) or decreasing (first > last). Ranges are also always inclusive.

A range is represented internally as a struct. However, the most common form of creating and matching on ranges is via the ../2 macro, auto-imported from Kernel:

iex> range = 1..3
iex> first..last = range
iex> first
iex> last

A range implements the Enumerable protocol, which means functions in the Enum module can be used to work with ranges:

iex> range = 1..10
iex> Enum.reduce(range, 0, fn i, acc -> i * i + acc end)
iex> Enum.count(range)
iex> Enum.member?(range, 11)
iex> Enum.member?(range, 8)

Link to this section Summary


Creates a new range

Link to this section Types

Link to this type t() View Source
t() :: %Range{first: integer(), last: integer()}
Link to this type t(first, last) View Source
t(first, last) :: %Range{first: first, last: last}

Link to this section Functions

Link to this function new(first, last) View Source
new(integer(), integer()) :: t()

Creates a new range.