Packages

This library is meant to provide an ergonomic way to match, compare and bind data in complex types such as maps and structs.

Current section

Files

Jump to
exmatch lib options.ex
Raw

lib/options.ex

defmodule ExMatch.Options do
defstruct [:opts]
def parse({:%{}, meta, opts_fields}, parse_ast) do
opts_fields =
Enum.map(opts_fields, fn {struct, struct_opts} ->
{[], map} = parse_ast.(struct_opts, %{})
{struct, map}
end)
opts = {:%{}, meta, opts_fields}
quote do
%ExMatch.Options{opts: unquote(opts)}
end
end
def parse(other, _parse_ast) do
cond do
Macro.quoted_literal?(other) ->
raise "options must be a map or an expression returning a map"
true ->
other
end
end
end