File tree 1 file changed +6
-0
lines changed
1 file changed +6
-0
lines changed Original file line number Diff line number Diff line change @@ -1266,13 +1266,16 @@ defmodule Enum do
1266
1266
def flat_map ( enumerable , fun ) do
1267
1267
reduce ( enumerable , [ ] , fn entry , acc ->
1268
1268
case fun . ( entry ) do
1269
+ [ ] -> acc
1269
1270
list when is_list ( list ) -> [ list | acc ]
1270
1271
other -> [ to_list ( other ) | acc ]
1271
1272
end
1272
1273
end )
1273
1274
|> flat_reverse ( [ ] )
1274
1275
end
1275
1276
1277
+ # the first clause is an optimization
1278
+ defp flat_reverse ( [ [ elem ] | t ] , acc ) , do: flat_reverse ( t , [ elem | acc ] )
1276
1279
defp flat_reverse ( [ h | t ] , acc ) , do: flat_reverse ( t , h ++ acc )
1277
1280
defp flat_reverse ( [ ] , acc ) , do: acc
1278
1281
@@ -4425,6 +4428,9 @@ defmodule Enum do
4425
4428
4426
4429
defp flat_map_list ( [ head | tail ] , fun ) do
4427
4430
case fun . ( head ) do
4431
+ # the two first clauses are an optimization
4432
+ [ ] -> flat_map_list ( tail , fun )
4433
+ [ elem ] -> [ elem | flat_map_list ( tail , fun ) ]
4428
4434
list when is_list ( list ) -> list ++ flat_map_list ( tail , fun )
4429
4435
other -> to_list ( other ) ++ flat_map_list ( tail , fun )
4430
4436
end
You can’t perform that action at this time.
0 commit comments