def ok_content({state, content}, struct) when is_struct(struct) do
assert struct = content
ok_content({state, content})
end
def ok_content({state, content}) do
assert state == :ok
content
end
But I get the warning: ‘variable “struct” is unused (there is a variable with the same name in the context, use the pin operator (^) to match on it or prefix this variable with underscore if it is not meant to be used)’
I tried the pin operator, but that seems to pin all the variables inside the struct as well, so it won’t work. The code seems to work, despite the warning, but I’m triggered by warnings and can’t leave them in the code…
doesn’t work because, as you noticed, the match operator can’t perform a partial match when the left-side term
is a pinned variable. In this chase, it checks whether struct is exactly equal to content, which is probably not what you want.
I assume you want to check whether content is of type struct?
Then I suspect your only option is to do it statically with: