Skip to content

Commit 789ad85

Browse files
committed
[Add] case statment example
1 parent cf09b2d commit 789ad85

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

case.exs

+13
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,16 @@ case {1, 2, 3} do
66
_ ->
77
IO.puts "This clause would match any value"
88
end
9+
10+
# Using case to test values against patterns
11+
12+
defmodule Account do
13+
def list_transactions(filename) do
14+
case File.read(filename) do
15+
{:ok, content}
16+
when byte_size(content) > 10 -> "Content: #{content}"
17+
{:ok, content} -> "Content: #{content}"
18+
{:error, type} -> "Error: #{type}"
19+
end
20+
end
21+
end

0 commit comments

Comments
 (0)