Skip to content

Normalize struct names #37

Description

@jiegillet

This is mentioned in #29.

Struct names should be replaced by placeholders as well.

Example input

defmodule Something do
  defstruct [:a, :b]
  def something(%Something{a: a}), do: %Something{a: 2 * a}
  def something_else(%__MODULE__{a: a}), do: %__MODULE__{a: 3 * a}
end

Desired output

defmodule(PLACEHOLDER_1) do
  defstruct([:a, :b])
  def(PLACEHOLDER_2(%PLACEHOLDER_1{a: PLACEHOLDER_3})) do
    %PLACEHOLDER_1{a: 2 * PLACEHOLDER_3}
  end
  def(PLACEHOLDER_4(%__MODULE__{a: PLACEHOLDER_3})) do
    %__MODULE__{a: 3 * PLACEHOLDER_3}
  end
end

I think __MODULE__ should not be replaced, because it means different things in different modules. It's already normalized, in a way...

Current output

defmodule(PLACEHOLDER_1) do
  defstruct([:a, :b])
  def(PLACEHOLDER_2(%Something{a: PLACEHOLDER_3})) do
    %Something{a: 2 * PLACEHOLDER_3}
  end
  def(PLACEHOLDER_4(%__MODULE__{a: PLACEHOLDER_3})) do
    %__MODULE__{a: 3 * PLACEHOLDER_3}
  end
end

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    x:action/improveImprove existing functionality/contentx:knowledge/elementaryLittle Exercism knowledge requiredx:module/representerWork on Representersx:size/largeLarge amount of workx:type/codingWrite code that is not student-facing content (e.g. test-runners, generators, but not exercises)

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions