Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions lib/elixir/lib/range.ex
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,7 @@ defmodule Range do

"""
@doc since: "1.14.0"
@spec shift(t, integer) :: t
def shift(first..last//step, steps_to_shift)
when is_integer(steps_to_shift) do
new(first + steps_to_shift * step, last + steps_to_shift * step, step)
Expand Down Expand Up @@ -364,6 +365,7 @@ defmodule Range do

"""
@doc since: "1.15.0"
@spec split(t, integer) :: {t, t}
def split(first..last//step = range, split) when is_integer(split) do
if split >= 0 do
split(first, last, step, split)
Expand Down Expand Up @@ -392,8 +394,17 @@ defmodule Range do

@doc """
Converts a range to a list.

## Examples

iex> Range.to_list(0..5)
[0, 1, 2, 3, 4, 5]
iex> Range.to_list(-3..0)
[-3, -2, -1, 0]

"""
@doc since: "1.15.0"
@spec to_list(t) :: list(integer)
def to_list(first..last//step)
when step > 0 and first <= last
when step < 0 and first >= last do
Expand Down