Hi there !
I was wondering if it was possible to quote a wildcard in order to do a kind of maybe in pattern matching.
I tried to define the following macro :
defmacro maybe(item) do
quote do
case unquote(item) do
nil -> quote do: _
_ -> unquote(item)
end
end
end
Then I was not able to use that in order to do pattern matching. I would like to do something like this :
|> Stream.filter(fn
({%NaiveDateTime{year: maybe(year)}, month: maybe(month), ...}, _}) -> true
(record) -> false
I am just wondering if I am taking the problem the right way. For now I wrap the code in functions with that pattern match each case, it makes a lot of duplication…
If anyone has any clue to do that right, I’m with !