Skip to content

@trymatch to return Some #184

@jariji

Description

@jariji

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions