gleam/bool

Types

Bool

A type with two possible values, True and False. Used to indicate whether things are... true or false!

Often is it clearer and offers more type safety to define a custom type than to use Bool. For example, rather than having a is_teacher: Bool field consider having a role: SchoolRole field where SchoolRole is a custom type that can be either Student or Teacher.

pub type Bool =
  Bool

Functions

compare

pub fn compare(a: Bool, with b: Bool) -> Order

Compares two bools and returns the first values Order to the second.

Examples

> import gleam/order
> compare(True, False)
order.Gt

max

pub fn max(a: Bool, b: Bool) -> Bool

Returns True if either bool value is True.

Examples

> max(True, False)
True

> max(False, True)
True

> max(False, False)
False

min

pub fn min(a: Bool, b: Bool) -> Bool

Returns False if either bool value is False.

Examples

> max(True, False)
False

> max(False, True)
False

> max(False, False)
False

negate

pub fn negate(bool: Bool) -> Bool

Returns the opposite bool value.

This is the same as the ! or not operators in some other languages.

Examples

> negate(True)
False

> negate(False)
True

to_int

pub fn to_int(bool: Bool) -> Int

Returns a numeric representation of the given bool.

Examples

> to_int(True)
1

> to_int(False)
0