Skip to content

Instantly share code, notes, and snippets.

@apboobalan
Last active October 14, 2020 04:22
Show Gist options
  • Save apboobalan/a42b82451dbc5b7fae6ca8616f02180a to your computer and use it in GitHub Desktop.
Save apboobalan/a42b82451dbc5b7fae6ca8616f02180a to your computer and use it in GitHub Desktop.
Curious case of 'in'. Add syntactic sugar while writing code.
defmodule Validator do
defmacro having({:in, _, [lhs, rhs]}) when lhs |> is_binary and rhs |> is_binary,
do: rhs |> String.contains?(lhs)
defmacro having({:in, _, [_lhs, _rhs]}), do: false
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment