From e1f0b67278ec1abeb6704f7ffe91deefffd4fedf Mon Sep 17 00:00:00 2001 From: Antoine Duchenet Date: Fri, 15 Sep 2023 09:17:53 +0200 Subject: [PATCH] refactor(phone-number): prefer cond to case for readability --- exercises/practice/phone-number/.meta/example.ex | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/exercises/practice/phone-number/.meta/example.ex b/exercises/practice/phone-number/.meta/example.ex index 14e192998..647e449d9 100644 --- a/exercises/practice/phone-number/.meta/example.ex +++ b/exercises/practice/phone-number/.meta/example.ex @@ -36,10 +36,12 @@ defmodule PhoneNumber do end defp validate_length(number) do - case String.length(number) do - invalid when invalid < 10 -> {:error, "must not be fewer than 10 digits"} - invalid when invalid > 11 -> {:error, "must not be greater than 11 digits"} - _valid -> {:ok, number} + length = String.length(number) + + cond do + length < 10 -> {:error, "must not be fewer than 10 digits"} + length > 11 -> {:error, "must not be greater than 11 digits"} + true -> {:ok, number} end end