next-ls
next-ls copied to clipboard
workspace command: inline a private function to an anonymous one
A workspace command that inlines a private function
Example:
defmodule Example do
def run(list) do
Enum.map(list, &square/1)
end
defp square(x) do
x * x
end
end
Hovering square in the run function should and using the workspace command should result in:
defmodule Example do
def run(list) do
square = fn x -> x * x end
Enum.map(list, square)
end
end
Consider the following scenarios:
- Any function calls to
square(3)should be converted to their anonymous counterpart:square.(3)
@NJichev i think that my expectation for this sort of refactor would be to actually inline the function with a lambda at the call sites.
so you example of
defmodule Example do
def run(list) do
Enum.map(list, &square/1)
end
defp square(x) do
x * x
end
end
would refactor to
defmodule Example do
def run(list) do
Enum.map(list, fn x -> x * x end)
end
end