From 75fd806f63da7955ac9ca673331c55c7e31e8b1f Mon Sep 17 00:00:00 2001 From: Artem Solomatin Date: Sat, 23 Sep 2023 00:56:08 +0300 Subject: [PATCH 1/2] Add typespecs and docs to 'Range' --- lib/elixir/lib/range.ex | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/lib/elixir/lib/range.ex b/lib/elixir/lib/range.ex index d9bb5cfc94c..54da73ff693 100644 --- a/lib/elixir/lib/range.ex +++ b/lib/elixir/lib/range.ex @@ -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) @@ -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) @@ -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 def to_list(first..last//step) when step > 0 and first <= last when step < 0 and first >= last do From 24404f97d47fbb8c4b2865fd3fb1ea2fefdd1884 Mon Sep 17 00:00:00 2001 From: Jean Klingler Date: Sat, 23 Sep 2023 08:11:05 +0900 Subject: [PATCH 2/2] More precise type --- lib/elixir/lib/range.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/elixir/lib/range.ex b/lib/elixir/lib/range.ex index 54da73ff693..ad86e609df0 100644 --- a/lib/elixir/lib/range.ex +++ b/lib/elixir/lib/range.ex @@ -404,7 +404,7 @@ defmodule Range do """ @doc since: "1.15.0" - @spec to_list(t) :: list + @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