From d64185ef6aec05033195e43c25b8d37385f5a54a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Mon, 11 Sep 2023 10:25:05 +0200 Subject: [PATCH] Apply suggestions from code review Co-authored-by: Andrea Leopardi --- .../pages/anti-patterns/design-anti-patterns.md | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/elixir/pages/anti-patterns/design-anti-patterns.md b/lib/elixir/pages/anti-patterns/design-anti-patterns.md index d3097f7ce4c..cd4b2715149 100644 --- a/lib/elixir/pages/anti-patterns/design-anti-patterns.md +++ b/lib/elixir/pages/anti-patterns/design-anti-patterns.md @@ -75,14 +75,15 @@ This anti-pattern refers to functions that receive options (for example, *keywor #### Example -An example of this anti-pattern, as shown below, is when a library (for example, `AlternativeInteger`) has a multi-clause function `parse/2` with many alternative return types. Depending on the options received as a parameter, the function will have a different return type. +An example of this anti-pattern, as shown below, is when a function has many alternative return types, depending on the options received as a parameter. ```elixir defmodule AlternativeInteger do - def parse(string, opts) when is_list(opts) do - case opts[:discard_rest] do - true -> String.to_integer(string) - _ -> Integer.parse(string) + def parse(string, options \\ []) when is_list(options) do + if Keyword.get(options, :discard_rest, false) do + String.to_integer(string) + else + Integer.parse(string) end end