Skip to content

Instantly share code, notes, and snippets.

@gkop
Created April 1, 2015 23:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gkop/5ea0185f5d3c9c410a5f to your computer and use it in GitHub Desktop.
Save gkop/5ea0185f5d3c9c410a5f to your computer and use it in GitHub Desktop.
Pattern match on struct type
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