exercism-elixir/bob/lib/bob.ex
2022-02-04 08:17:11 -04:00

17 lines
560 B
Elixir

defmodule Bob do
@spec hey(String.t()) :: String.t()
def hey(input) do
letter? = &(String.upcase(&1) != String.downcase(&1))
shouting? = &(&1 == String.upcase(&1) and letter?.(&1))
question? = &(String.trim(&1) |> String.ends_with?("?"))
blank? = &(String.trim(&1) == "")
cond do
blank?.(input) -> "Fine. Be that way!"
shouting?.(input) and question?.(input) -> "Calm down, I know what I'm doing!"
shouting?.(input) -> "Whoa, chill out!"
question?.(input) -> "Sure."
true -> "Whatever."
end
end
end