Test one pattern with if let

if let pattern = expression evaluates the initializer once, then runs the true branch only when the refutable pattern matches. New bindings exist only in that branch.

Use it for a single success path. A full match is clearer when several cases carry useful information.

fn main() {
  let answer: Optional<int> = some(42)
  if let some(value) = answer {
    println(value)
  } else {
    println("missing")
  }
}
Output & diagnostics
Expected:
42
Ctrl/⌘+Enter runs the current lesson.