next-ls icon indicating copy to clipboard operation
next-ls copied to clipboard

workspace command: inline a private function to an anonymous one

Open NJichev opened this issue 1 year ago • 1 comments

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 avatar Apr 24 '24 16:04 NJichev

@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

mhanberg avatar Apr 24 '24 17:04 mhanberg