`@trymatch` to return `Some`
Opened this issue · 0 comments
jariji commented
Suppose I am trying to write an ast transformation.
using MacroTools: postwalk
postwalk(expr) do e
r = @trymatch e begin
:($f($x)) => Some(x)
:($g($x)) => Some(x)
end
@match r begin
nothing => e
Some(x) => x
end
end
Note Some(x)
is necessary because otherwise it is impossible to distinguish between "the value happened to be nothing
" and "matching failed". It would be a little nicer if @trymatch
did the Some(x)
automatically because (1) it is convenient for users who use Some
anyway and (2) it will lead users toward correct usage; currently it is too easy to accidentally forget Some
which may lose information.