Xo is experimental. The source is now public on GitHub, or try Xo in your browser.
Menu · XO0906

Docs

XO0906: a match that `??` writes shorter

note · reported by the vet

Reported by xo vet, not xo check. match opt { Some(v) => v None => return r } (or continue, break) is the Option form of opt ?? return r: the right side of ?? may leave the function or the loop. On a Result, match r { Ok(v) => v Err(e) => return w } is r ?? e => return w (Err(_) gives _ =>). The fix rewrites it.

Example

fn first(xs: List[Int]) -> Int? {
  let v = match xs.first() {
    Some(x) => x
    None => return None
  }
  Some(v)
}

Fix

fn first(xs: List[Int]) -> Int? {
  let v = xs.first() ?? return None
  Some(v)
}

Run xo explain XO0906 for this text in a terminal, or see section 10.6 of the specification.