Version 1 (greeter1.ex - line #4) :ok <- validate(name) do
Version 2 (greeter2.ex - line #4) {:ok, name} <- validate(name) do
I believe version 1 is the best, I’m only checking to see if my value is valid and not changing it, though version 2 is more consistent with the rest of the code. (always returning a tuple)
I would go with the second option, seems more consistent with other functions returns, and even consistent with itself if you decide do return {:error, "the message"} when the validation fails.
validate/1 will either return :ok or {:error, "Too short"} in the first version but I can’t shake the feeling that returning {:ok, name} in validate/1 (second version) is kinda senseless.
Well, I share your opinion here, it’s kinda senseless in this case, but I really think that maintaining the same return type for the functions is good.