Skip to content

Instantly share code, notes, and snippets.

@elbow-jason
Created February 11, 2018 18:50
Show Gist options
  • Save elbow-jason/aa8ebc350b0379f6160c82b69f7a8db8 to your computer and use it in GitHub Desktop.
Save elbow-jason/aa8ebc350b0379f6160c82b69f7a8db8 to your computer and use it in GitHub Desktop.
match a collection using pattern matching
defmodule Matcher do
defmacro match_any?(pattern, collection) do
quote do
Enum.any?(unquote(collection), fn item ->
case item do
unquote(pattern) -> true
_ -> false
end
end)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment