Skip to content

Define @trymatch and @tryswitch #131

Closed
@serenity4

Description

I think it would be a good addition to have versions of @trymatch and @tryswitch that allow having no matches, like for example

@trymatch x begin
  ::Int => :int
end

# would be equivalent to

@match x begin
  ::Int => :int
  _ => nothing
end

and

@tryswitch x begin
  @case ::Int
    println("int")
end

# would be equivalent to

@switch x begin
  @case ::Int
    println("int")
  @case _
    nothing
end

The main advantage with these is when you have nested @match and @switch statements, where each invocation will require adding this special case for no matches. The name should make it fairly obvious that it will silently "fail".

If it's not already implemented (I looked around, but we never know) I can submit a PR to define these helper macros.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions