mirror of
https://github.com/adambard/learnxinyminutes-docs.git
synced 2024-11-27 04:44:08 +03:00
Merge pull request #3270 from chriszimmerman/GH-2594-elixir-clauses
[Elixir/en] - #2594 - Adds clarification for functions with multiple clauses.
This commit is contained in:
commit
7b77c76450
@ -287,7 +287,11 @@ end
|
||||
PrivateMath.sum(1, 2) #=> 3
|
||||
# PrivateMath.do_sum(1, 2) #=> ** (UndefinedFunctionError)
|
||||
|
||||
# Function declarations also support guards and multiple clauses:
|
||||
# Function declarations also support guards and multiple clauses.
|
||||
# When a function with multiple clauses is called, the first function
|
||||
# that satisfies the clause will be invoked.
|
||||
# Example: invoking area({:circle, 3}) will call the second area
|
||||
# function defined below, not the first:
|
||||
defmodule Geometry do
|
||||
def area({:rectangle, w, h}) do
|
||||
w * h
|
||||
|
Loading…
Reference in New Issue
Block a user