-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.ex
32 lines (25 loc) · 642 Bytes
/
test.ex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
defmodule MyProject do
@spec add(number(), number()) :: number()
def add(a,b) do
a + b
end
@spec add(number(), number()) :: number()
def subtract(a,b) do
a - b
end
def list_length([]), do: 0
def list_length([_ | tail]), do: 1 + list_length(tail)
def hello(names, lang \\ "en")
def hello(names, lang) when is_list(names) do
names
|> Enum.join(", ")
|> hello
end
def hello(name, lang) when is_binary(name) do
phrase(lang) <> name
end
defp phrase("en"), do: "Hello, "
defp phrase("es"), do: "Hola, "
defp phrase("fr"), do: "Allo, "
defp phrase("gr"), do: "Χαίρεται, "
end