Answers for "elixir read tuples"

0

elixir read tuples

message = { :ok, "To improve is to change; to be perfect is to change often.", author: "Winston Churchill" }
# use the elem function to read values from a tuple
status = elem(message, 0)
message = elem(message, 1)
author = elem(message, 2)[:author]

message = { :ok, "To improve is to change; to be perfect is to change often.", author: "Winston Churchill" }
# set the values on status, message, and author with pattern matching
{ status, message, author: author } = message
Posted by: Guest on January-15-2021

Browse Popular Code Answers by Language