Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
Co-authored-by: Eksperimental <[email protected]>
  • Loading branch information
josevalim and eksperimental authored Sep 11, 2023
1 parent 60a1282 commit 4e2be8c
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions lib/elixir/pages/anti-patterns/design-anti-patterns.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,10 @@ defmodule AlternativeInteger do
if Keyword.get(options, :discard_rest, false) do
String.to_integer(string)
else
Integer.parse(string)
case String.parse(string) do
{int, _rest} -> int
:error -> :error
end
end
end
end
Expand All @@ -105,13 +108,15 @@ To refactor this anti-pattern, as shown next, add a specific function for each r

```elixir
defmodule AlternativeInteger do
def parse_no_rest(string) do
String.to_integer(string)
end

@spec parse(String.t()) :: {integer(), rest :: String.t()} | :error
def parse(string) do
Integer.parse(string)
end

@spec parse_discard_rest(String.t()) :: integer()
def parse_discard_rest(string) do
String.to_integer(string)
end
end
```

Expand Down

0 comments on commit 4e2be8c

Please sign in to comment.