5.4 Conditions
let kind = if n < 0 { "neg" } else if n == 0 { "zero" } else { "pos" }
if let User{ role: .Admin, name, .. } = u { greet(name) }
if x is Receipt { save(x) } // x is narrowed to ReceiptThere is no ternary operator. An if without else has type ().
- The type of
if/matchis the common expected type if the context gives one, otherwise the union of the branch types (if c { s } else { EmptyCart{} }has typeCartSnapshot | EmptyCart). e is P— a check against pattern P (§5.5) as a boolean expression. The pattern bindings are visible in theifbranch and in the right-hand part of&&:if caller is .User(id: uid, ..) && uid == owner { … }. An enum variant inisis written with a dot (.User) so as not to confuse it with a type.
See also
Source: docs/spec/oxl-standard.en.md