Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

workspace command: inline a private function to an anonymous one #437

Open
NJichev opened this issue Apr 24, 2024 · 1 comment
Open

workspace command: inline a private function to an anonymous one #437

NJichev opened this issue Apr 24, 2024 · 1 comment
Labels
enhancement New feature or request good first issue Good for newcomers workspace-command

Comments

@NJichev
Copy link
Collaborator

NJichev commented Apr 24, 2024

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 NJichev added enhancement New feature or request workspace-command labels Apr 24, 2024
@NJichev NJichev changed the title workspace command: inline a private function workspace command: inline a private function to an anonymous one Apr 24, 2024
@NJichev NJichev added the good first issue Good for newcomers label Apr 24, 2024
@mhanberg
Copy link
Collaborator

@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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers workspace-command
Projects
None yet
Development

No branches or pull requests

2 participants