Skip to content

Conversation

@feliciofilipe
Copy link
Member

No description provided.

defmodule ExToolkit.Roman do
@valid_romans ["I", "V", "X", "L", "C", "D", "M"]

def is_valid_roman(string) do
Copy link
Member

@nelsonmestevao nelsonmestevao Feb 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Member

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 ☝️

@nelsonmestevao nelsonmestevao changed the title feat(naming): improve extract_fist_last_name feat(naming): add support for roman numbers and jr suffix in extract_fist_last_name Feb 10, 2024
@nelsonmestevao nelsonmestevao changed the title feat(naming): add support for roman numbers and jr suffix in extract_fist_last_name feat(naming): add support for roman numbers and jr suffix in extract_fist_last_name/1 Feb 10, 2024
@nelsonmestevao nelsonmestevao changed the title feat(naming): add support for roman numbers and jr suffix in extract_fist_last_name/1 feat(naming): add support for roman numbers and jr suffix in extract_first_last_name/1 Feb 10, 2024
@@ -0,0 +1,20 @@
defmodule ExToolkit.Roman do
Copy link
Member

@nelsonmestevao nelsonmestevao Feb 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)
Copy link
Member

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.

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Member

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 💡

Comment on lines +11 to +12
defp is_valid_roman([], _), do: true

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
defp is_valid_roman([], _), do: true

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.

3 participants