Otera.Range (otera v0.2.0)

Copy Markdown View Source

The Python range object that range() gives in a template.

It prints as range(0, 3), has a length, takes an index or a slice, supports in, and gives its items when a template iterates over it. A slice of a range is a range.

Summary

Functions

Returns {:ok, item} for the item at index, which can be negative, or :error.

Returns true if item is an item of range. An integer is an item when the arithmetic of the range gives it, and another value when it equals an item.

Returns the Python repr() of range, such as range(0, 3) or range(0, 10, 2).

Returns the number of items of range.

Returns range[start:stop:step] as a range, where start and stop are the bounds that slice.indices gives for the length of range.

Returns the items of range as a list.

Types

t()

@type t() :: %Otera.Range{start: integer(), step: integer(), stop: integer()}

Functions

fetch(range, index)

@spec fetch(t(), integer()) :: {:ok, integer()} | :error

Returns {:ok, item} for the item at index, which can be negative, or :error.

member?(range, item)

@spec member?(t(), term()) :: boolean()

Returns true if item is an item of range. An integer is an item when the arithmetic of the range gives it, and another value when it equals an item.

repr(range)

@spec repr(t()) :: String.t()

Returns the Python repr() of range, such as range(0, 3) or range(0, 10, 2).

size(range)

@spec size(t()) :: non_neg_integer()

Returns the number of items of range.

slice(range, start, stop, step)

@spec slice(t(), integer(), integer(), integer()) :: t()

Returns range[start:stop:step] as a range, where start and stop are the bounds that slice.indices gives for the length of range.

to_list(range)

@spec to_list(t()) :: [integer()]

Returns the items of range as a list.