Home / Docs / Standard library / Prelude

is_ok

Release v0.4.0Edition 0.1 and later

A function of the prelude, in scope in every module. Edition 0.1 and later.

una
pub is_ok[T, E](r: Result[T, E]) -> Bool
  ensures result == (r is Ok)

Whether r is Ok (spec/14 §1).

Parameters

Returns

Bool: true exactly when r is Ok.

See also

Result

Example

src/shop.unauna
module shop

--- Whether a quantity was accepted.
checked_quantity(units: Int) -> Result[Int, Text] = if units > 0 then Ok(units) else Err("no units")

pub main() -> Unit
  uses @console: Console[print]
=
  let accepted = checked_quantity(0).is_ok()
  @console.print("accepted: {accepted}")

una run . prints:

Output
accepted: false

Specification

Generated from the standard modules of una v0.4.0 (docs/std/listing.json, which is not part of the specification). The specification governs: spec/14 §1.