Tutorial by Examples

case {1, 2} do {3, 4} -> "This clause won't match." {1, x} -> "This clause will match and bind x to 2 in this clause." _ -> "This clause would match any value." end case is only used to match the given pattern of the particular data...
if true do "Will be seen since condition is true." end if false do "Won't be seen since condition is false." else "Will be seen. end unless false do "Will be seen." end unless true do "Won't be seen." else ...
cond do 0 == 1 -> IO.puts "0 = 1" 2 == 1 + 1 -> IO.puts "1 + 1 = 2" 3 == 1 + 2 -> IO.puts "1 + 2 = 3" end # Outputs "1 + 1 = 2" (first condition evaluating to true) cond will raise a CondClauseError if no conditions are true. co...
with clause is used to combine matching clauses. It looks like we combine anonymous functions or handle function with multiple bodies (matching clauses). Consider the case: we create a user, insert it into DB, then create greet email and then send it to the user. Without the with clause we might ...

Page 1 of 1