Skip to content

Replace unless/2 usages in the codebase #13808

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

Merged
merged 1 commit into from
Sep 6, 2024

Conversation

sabiwara
Copy link
Contributor

@sabiwara sabiwara commented Sep 6, 2024

Extracted from the implementation of the :migrate option itself (#13769), for a leaner diff and simpler discussion.


Thinking aloud: in the same way we're compiling !!x as a single case, we could do the same thing for if !x and if not x, making it equivalent to unless (or a more strict version of it in the case of not).

So instead of

case (case x do
        var2 when var2 === false or var2 === nil -> true
        _ -> false
      end) do
  false -> nil
  true -> 0
end

if !x, do: 0 would generate

case x do
  var2 when var2 === false or var2 === nil -> 0
  _ -> nil
end

Thoughts? I can send a follow-up PR for this.

@sabiwara sabiwara merged commit 1286a62 into elixir-lang:main Sep 6, 2024
9 checks passed
@sabiwara sabiwara deleted the rm-unless branch September 6, 2024 07:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants