Skip to content

Replace conditionals in match with #:whenΒ #389

@jackfirth

Description

@jackfirth

Saw a few cases in racket/typed-racket#1410 where #:when would clean up various bits of pattern matching code:

#lang resyntax/test

test: "original code should be refactorable to new code"
--------------------
#lang racket
(define (f pt)
  (match pt
    [(list x y)
     (if (> x y)
         (list y x)
         pt)]
    [(list) '()]))
--------------------
--------------------
#lang racket
(define (f pt)
  (match pt
    [(list x y)
     #:when (> x y)
     (list y x)]
    [(list x y) pt]
    [(list) '()]))
--------------------

This should probably only trigger when the pattern is small. It should also only trigger on match expressions that already have multiple branches, since the single-branch case would be clearer as a match-define. A two-case cond instead of an if should also count.

Metadata

Metadata

Assignees

Labels

good first issueGood for newcomersnew lintIssues suggesting new lints or pull requests implementing new lints

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions