-
Notifications
You must be signed in to change notification settings - Fork 0
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
feat(naming): add support for roman numbers and jr suffix in extract_first_last_name/1 #2
base: main
Are you sure you want to change the base?
Conversation
defmodule ExToolkit.Roman do | ||
@valid_romans ["I", "V", "X", "L", "C", "D", "M"] | ||
|
||
def is_valid_roman(string) do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
def is_valid_roman(string) do | |
@spec is_valid_roman(String.t()) :: boolean() | |
def is_valid_roman(string) when is_binary(string) do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't forget documentation and unit tests ☝️
@@ -0,0 +1,20 @@ | |||
defmodule ExToolkit.Roman do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This does not make sense since you are using directly @valid_romans
in the bottom case. You just need a guard.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And then you can just pipe it in the original case without the extra aux function 💡
defp is_valid_roman([], _), do: true | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
defp is_valid_roman([], _), do: true |
No description provided.