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:
Divay Prakash 2018-10-08 23:14:54 +05:30 committed by GitHub
commit 7b77c76450
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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