ProgrammingElixir1.6-MyTurns/Functions-4.exs

19 lines
552 B
Elixir
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# Write a function prefix that takes a string. It should return a new function that takes a second string.
# When that second function is called, it will return a string containing the first string, a space, and the second string.
#
#   iex> mrs = prefix.("Mrs")
#   #Function<erl_eval.6.82930912>
#   iex> mrs.("Smith")
#   "Mrs Smith"
#   iex> prefix.("Elixir").("Rocks")
#   "Elixir Rocks"”
prefix = fn p ->
fn s ->
"#{p} #{s}"
end
end
mrs = prefix.("Mrs")
IO.puts mrs.("Smith")
IO.puts prefix.("Elixir").("Rocks")