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

Refactoring of RuneFinder.select/2 #1

Merged
merged 1 commit into from
Dec 31, 2023
Merged

Conversation

gVirtu
Copy link
Contributor

@gVirtu gVirtu commented May 26, 2019

Firstly, congratulations on your talk on ElixirBrasil 2019! 😸

Given your invitation to review and comment on your code, I thought I would pitch in.

Overall, I'd say it looks great! A tiny simplification I'd make is in the use of Enum.reduce. It is tremendously flexible as you know but not always the easiest function to read or skim through. Fortunately, some of the main use cases for it were already implemented in the Enum library, and count/2 sugars the implementation really well here. It returns the number of elements which evaluated to true given the function in the second parameter.

Now, for the side effect of calling display on valid elements there are several approaches, I chose to leverage short-circuiting in order to keep it a one liner check. It works as long as display returns a truthy value.

Hope you keep thriving on Elixir!

@ramalho
Copy link
Owner

ramalho commented Dec 31, 2023

Thanks for your contribution and the words of encouragement @gVirtu! I adopted your Enum.count/2 suggestion, thanks for that! Memorizing all the goodness in the Enum library seems like a very good idea. I don't line the use of short-circuit and to perform the duty of an if in this example, but I will rewrite the if in one line.

BTW, I paused my Elixir studies in 2019, but I am coming back to the language in 2024.

@ramalho ramalho merged commit b5fd39d into ramalho:master Dec 31, 2023
ramalho added a commit that referenced this pull request Dec 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants