Skip to content

Commit cf61958

Browse files
author
José Valim
committed
No need to reverse a list when building an iolist
1 parent c639b01 commit cf61958

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

lib/elixir/lib/enum.ex

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -937,13 +937,13 @@ defmodule Enum do
937937

938938
def join(collection, joiner) when is_binary(joiner) do
939939
reduced = reduce(collection, :first, fn
940-
entry, :first -> [enum_to_string(entry)]
941-
entry, acc -> [enum_to_string(entry), joiner|acc]
940+
entry, :first -> enum_to_string(entry)
941+
entry, acc -> [acc, joiner|enum_to_string(entry)]
942942
end)
943943
if reduced == :first do
944944
""
945945
else
946-
IO.chardata_to_string :lists.reverse(reduced)
946+
IO.chardata_to_string reduced
947947
end
948948
end
949949

@@ -996,14 +996,14 @@ defmodule Enum do
996996

997997
def map_join(collection, joiner, mapper) when is_binary(joiner) do
998998
reduced = reduce(collection, :first, fn
999-
entry, :first -> [enum_to_string(mapper.(entry))]
1000-
entry, acc -> [enum_to_string(mapper.(entry)), joiner|acc]
999+
entry, :first -> enum_to_string(mapper.(entry))
1000+
entry, acc -> [acc, joiner|enum_to_string(mapper.(entry))]
10011001
end)
10021002

10031003
if reduced == :first do
10041004
""
10051005
else
1006-
IO.chardata_to_string :lists.reverse(reduced)
1006+
IO.chardata_to_string reduced
10071007
end
10081008
end
10091009

0 commit comments

Comments
 (0)