Grav v1.14.0

Bool

import "std/types" (included in import "std") · namespace std.types

Bool parses the usual ways of writing a truth value and converts bools, as methods of any bool.

grav
import "std"

fn main() {
    print("${Bool.parse("yes")} ${Bool.parse("OFF")} ${Bool.tryParse("maybe") == null}")
    print("${true.toInt()} ${false.toYesNo()} ${true.toOnOff()} ${"1" as bool}")
}
Output
true false true
1 no on true

API

class Bool

Truth values (see the top of this file).

Static members

  • static fn parse(s: string) -> bool — "true"/"false", "t"/"f", "yes"/"no", "y"/"n", "on"/"off", "1"/"0" (any case); ValueError for anything else.
  • static fn tryParse(s: string) -> bool? — As parse, but null for anything else.
  • static fn compare(a: bool, b: bool) -> int — A comparator for sorting: false before true.
  • static fn descending(a: bool, b: bool) -> int
  • static fn compareTo(a: bool, b: bool) -> int
  • static fn toInt(b: bool) -> int — 1 or 0.
  • static fn toString(b: bool) -> string — "true" or "false".
  • static fn toYesNo(b: bool) -> string — "yes" or "no".
  • static fn toOnOff(b: bool) -> string — "on" or "off".
  • static fn xor(a: bool, b: bool) -> bool — Whether exactly one of the two is true.
  • static fn implies(a: bool, b: bool) -> bool — a implies b: false only when a is true and b is false.

Edit this page on GitHub