#pattern-matching Clear
Tags #php #kotlin #bash #go #sql #rust #typescript #html #java #python #files #utils #strings #http #concurrency #async #json #arrays #security #types #crypto #database #dates #format
Rust match with Guards, Ranges, and Bindings
`match` arms can have `if` guards, range patterns (`1..=5`), bindings (`x @ pattern`), and ORs (`A | B`). Combine them for very expressive dispatch.
Java Pattern Matching for instanceof (Java 16+)
Combine `instanceof` with a variable binding — no separate cast needed. Eliminates the most common "check then cast" bug pattern and is significantly less verbose.
Java Sealed Classes + Pattern Matching (Java 21+)
`sealed` restricts which classes can extend a type — perfect for closed hierarchies that pattern matching can switch over exhaustively. The compiler enforces that you handle every variant.
Rust if let / while let
When you only care about one variant, `if let` is shorter than `match`. `while let` keeps looping as long as the pattern matches — great for draining iterators or option-returning APIs.