Created
April 1, 2015 23:34
-
-
Save gkop/5ea0185f5d3c9c410a5f to your computer and use it in GitHub Desktop.
Pattern match on struct type
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule Bar do | |
defstruct herp: "Derp" | |
end | |
defmodule Baz do | |
defstruct herp: "Derp" | |
end | |
defmodule Foo do | |
def start_link do | |
Task.start_link(fn -> loop end) | |
end | |
defp loop do | |
receive do | |
{%{__struct__: Bar}, caller} -> | |
send caller, "bar" | |
loop | |
{%{__struct__: Baz}, caller} -> | |
send caller, "baz" | |
loop | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment