3 ms·
So does Haskell and Rust. It's called exhaustive pattern matching on sum types with the Maybe monad (or Optional). I believe Haskell popularized this syntax an
by deltaonefour 4y ago
So does Haskell and Rust.
It's called exhaustive pattern matching on sum types with the Maybe monad (or Optional). I believe Haskell popularized this syntax and Rust and Swift borrowed it from Haskell. Strictly speaking though, haskell pattern matching isn't exhaustive but the compiler will give you a warning if your code doesn't handle every case.
Elm is another language that exploits this feature to a scale where unless you use the FFI, elm programs cannot logically ever crash.