Skip to content

Commit f71f37e

Browse files
eksperimentaljosevalim
authored andcommitted
Remove Integer.to_string/1 and Integer.to_charlist/1 (#8777)
They are not needed, since they are covered by their /2 version.
1 parent ff96fa2 commit f71f37e

File tree

2 files changed

+13
-50
lines changed

2 files changed

+13
-50
lines changed

lib/elixir/lib/integer.ex

Lines changed: 8 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -323,12 +323,13 @@ defmodule Integer do
323323
# Please reapply commit 2622fd6b0aa419a983a899a1fbdb5deefba3d85d.
324324
@doc """
325325
Returns a binary which corresponds to the text representation
326-
of `integer`.
326+
of `integer` in the given `base`.
327+
328+
`base` can be an integer between 2 and 36. If no `base` is given, it defaults to `10`.
327329
328330
Inlined by the compiler.
329331
330332
## Examples
331-
332333
iex> Integer.to_string(123)
333334
"123"
334335
@@ -341,22 +342,6 @@ defmodule Integer do
341342
iex> Integer.to_string(0123)
342343
"123"
343344
344-
"""
345-
@spec to_string(integer) :: String.t()
346-
def to_string(integer) do
347-
:erlang.integer_to_binary(integer)
348-
end
349-
350-
@doc """
351-
Returns a binary which corresponds to the text representation
352-
of `integer` in the given `base`.
353-
354-
`base` can be an integer between 2 and 36.
355-
356-
Inlined by the compiler.
357-
358-
## Examples
359-
360345
iex> Integer.to_string(100, 16)
361346
"64"
362347
@@ -368,15 +353,17 @@ defmodule Integer do
368353
369354
"""
370355
@spec to_string(integer, 2..36) :: String.t()
371-
def to_string(integer, base) do
356+
def to_string(integer, base \\ 10) do
372357
:erlang.integer_to_binary(integer, base)
373358
end
374359

375360
# TODO: Remove Integer.to_charlist/1 once the minimum supported version is
376361
# Erlang/OTP 22, since it is covered by the now BIF Integer.to_charlist/2.
377362
# Please reapply commit 2622fd6b0aa419a983a899a1fbdb5deefba3d85d.
378363
@doc """
379-
Returns a charlist which corresponds to the text representation of the given `integer`.
364+
Returns a charlist which corresponds to the text representation of `integer` in the given `base`.
365+
366+
`base` can be an integer between 2 and 36. If no `base` is given, it defaults to `10`.
380367
381368
Inlined by the compiler.
382369
@@ -394,21 +381,6 @@ defmodule Integer do
394381
iex> Integer.to_charlist(0123)
395382
'123'
396383
397-
"""
398-
@spec to_charlist(integer) :: charlist
399-
def to_charlist(integer) do
400-
:erlang.integer_to_list(integer)
401-
end
402-
403-
@doc """
404-
Returns a charlist which corresponds to the text representation of `integer` in the given `base`.
405-
406-
`base` can be an integer between 2 and 36.
407-
408-
Inlined by the compiler.
409-
410-
## Examples
411-
412384
iex> Integer.to_charlist(100, 16)
413385
'64'
414386
@@ -420,7 +392,7 @@ defmodule Integer do
420392
421393
"""
422394
@spec to_charlist(integer, 2..36) :: charlist
423-
def to_charlist(integer, base) do
395+
def to_charlist(integer, base \\ 10) do
424396
:erlang.integer_to_list(integer, base)
425397
end
426398

lib/elixir/test/elixir/integer_test.exs

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ defmodule IntegerTest do
152152
assert_raise ArgumentError, "invalid base nil", fn -> Integer.parse("2", nil) end
153153
end
154154

155-
test "to_string/1" do
155+
test "to_string/2" do
156156
assert Integer.to_string(42) == "42"
157157
assert Integer.to_string(+42) == "42"
158158
assert Integer.to_string(-42) == "-42"
@@ -163,9 +163,7 @@ defmodule IntegerTest do
163163
Integer.to_string(n)
164164
end
165165
end
166-
end
167166

168-
test "to_string/2" do
169167
assert Integer.to_string(42, 2) == "101010"
170168
assert Integer.to_string(42, 10) == "42"
171169
assert Integer.to_string(42, 16) == "2A"
@@ -190,7 +188,9 @@ defmodule IntegerTest do
190188
end
191189
end
192190

193-
test "to_charlist/1" do
191+
test "to_charlist/2" do
192+
module = Integer
193+
194194
assert Integer.to_charlist(42) == '42'
195195
assert Integer.to_charlist(+42) == '42'
196196
assert Integer.to_charlist(-42) == '-42'
@@ -201,14 +201,10 @@ defmodule IntegerTest do
201201
Integer.to_charlist(n)
202202
end
203203
end
204-
end
205204

206-
test "to_char_list/1" do
207-
module = Integer
208205
assert module.to_char_list(42) == '42'
209-
end
206+
assert module.to_char_list(42, 2) == '101010'
210207

211-
test "to_charlist/2" do
212208
assert Integer.to_charlist(42, 2) == '101010'
213209
assert Integer.to_charlist(42, 10) == '42'
214210
assert Integer.to_charlist(42, 16) == '2A'
@@ -233,11 +229,6 @@ defmodule IntegerTest do
233229
end
234230
end
235231

236-
test "to_char_list/2" do
237-
module = Integer
238-
assert module.to_char_list(42, 2) == '101010'
239-
end
240-
241232
test "gcd/2" do
242233
assert Integer.gcd(1, 5) == 1
243234
assert Integer.gcd(2, 3) == 1

0 commit comments

Comments
 (0)