feat(naming): add support for roman numbers and jr suffix in extract_first_last_name/1#2
Open
feliciofilipe wants to merge 1 commit intomainfrom
Open
feat(naming): add support for roman numbers and jr suffix in extract_first_last_name/1#2feliciofilipe wants to merge 1 commit intomainfrom
feliciofilipe wants to merge 1 commit intomainfrom
Conversation
| defmodule ExToolkit.Roman do | ||
| @valid_romans ["I", "V", "X", "L", "C", "D", "M"] | ||
|
|
||
| def is_valid_roman(string) do |
Member
There was a problem hiding this comment.
Suggested change
| def is_valid_roman(string) do | |
| @spec is_valid_roman(String.t()) :: boolean() | |
| def is_valid_roman(string) when is_binary(string) do |
Member
There was a problem hiding this comment.
Don't forget documentation and unit tests ☝️
| @@ -0,0 +1,20 @@ | |||
| defmodule ExToolkit.Roman do | |||
Member
There was a problem hiding this comment.
Suggested change
| defmodule ExToolkit.Roman do | |
| defmodule ExToolkit.NumeralSystems.Roman do |
And then we can replace is_valid_roman/1 with just valid?/1, what do you think?
| string | ||
| |> String.upcase() | ||
| |> String.graphemes() | ||
| |> is_valid_roman(@valid_romans) |
Member
There was a problem hiding this comment.
This does not make sense since you are using directly @valid_romans in the bottom case. You just need a guard.
Comment on lines
+13
to
+19
| defp is_valid_roman([head | tail], valid_romans) do | ||
| if Enum.member?(@valid_romans, head) do | ||
| is_valid_roman(tail, valid_romans) | ||
| else | ||
| false | ||
| end | ||
| end |
Member
There was a problem hiding this comment.
Suggested change
| defp is_valid_roman([head | tail], valid_romans) do | |
| if Enum.member?(@valid_romans, head) do | |
| is_valid_roman(tail, valid_romans) | |
| else | |
| false | |
| end | |
| end | |
| defp is_valid_roman(graphenes) when is_list(graphenes) do | |
| Enum.all?(graphenes, &(&1 in @valid_romans)) | |
| end |
Member
There was a problem hiding this comment.
And then you can just pipe it in the original case without the extra aux function 💡
Comment on lines
+11
to
+12
| defp is_valid_roman([], _), do: true | ||
|
|
Member
There was a problem hiding this comment.
Suggested change
| defp is_valid_roman([], _), do: true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.