Elixir: Module: case

Using ‘case’ construct to compare a list of atoms

nick3499
1 min readJun 30, 2017

In the example code above, case compares the atom name passed to the function in the planemo variable with the listed atom names (see interaction below). When an atom match is found, a following expression is executed, directed by the flow control operator ->.

iex(1)> c("drop.ex")
[Drop]
iex(2)> Drop.fall_velocity(:earth,20)
19.79898987322333

In the interpreter example above, the atom named :earth and the distance value of 20 are passed to the Drop module’s function fall_velocity().

--

--

nick3499
nick3499

Written by nick3499

coder of JavaScript and Python

No responses yet