Bool
A Bool is TRUE or FALSE, never NA. R’s operators already cover most of this module;
its functions exist so that a boolean step can be passed by name, as in List.walk(flags, Bool.true, Bool.and), and so that code written against Roc’s names reads the same.
| Function | Summary |
|---|---|
Bool.true |
TRUE, as Roc spells it. |
Bool.false |
FALSE. |
Bool.from_r |
Converts an R logical into a Bool, refusing NA and a length other than one. |
Bool.and |
Whether both are TRUE. |
Bool.or |
Whether either is TRUE. |
Bool.not |
The opposite value. |
Bool.is_eq |
Whether two values are equal by identical(), the library’s equality. |
Bool.is_not_eq |
Whether two values differ by identical(). |
Bool.true
Section titled “Bool.true”#: BoolBool.trueTRUE, as Roc spells it. It is a value, not a function.
Bool.true#> TRUEBool.false
Section titled “Bool.false”#: BoolBool.falseFALSE.
Bool.false#> FALSEBool.from_r
Section titled “Bool.from_r”Bool.from_r <- function(value: logical) -> Bool#: fn(value: logical) -> BoolBool.from_r <- function(value)Converts an R logical into a Bool, refusing NA and a length other than one.
Bool.and
Section titled “Bool.and”Bool.and <- function(first: Bool, second: Bool) -> Bool#: fn(first: Bool, second: Bool) -> BoolBool.and <- function(first, second)Whether both are TRUE. Both arguments are evaluated, unlike with &&.
Bool.and(TRUE, FALSE)#> FALSEBool.or
Section titled “Bool.or”Bool.or <- function(first: Bool, second: Bool) -> Bool#: fn(first: Bool, second: Bool) -> BoolBool.or <- function(first, second)Whether either is TRUE. Both arguments are evaluated, unlike with ||.
Bool.or(TRUE, FALSE)#> TRUEBool.not
Section titled “Bool.not”Bool.not <- function(value: Bool) -> Bool#: fn(value: Bool) -> BoolBool.not <- function(value)The opposite value.
List.keep_if([1, 2, 3], function(x) Bool.not(Num.is_even(x)))#> [1i64, 3i64]Bool.is_eq
Section titled “Bool.is_eq”Bool.is_eq <- function<T: eq>(first: T, second: T) -> Bool#: <T: eq> fn(first: T, second: T) -> BoolBool.is_eq <- function(first, second)Whether two values are equal by identical(), the library’s equality. An integer and a double
are never identical, so Bool.is_eq(1L, 1) is FALSE, and a dictionary or set compares without
regard to order.
Bool.is_eq(Set.from_list([1, 2]), Set.from_list([2, 1]))#> TRUEBool.is_not_eq
Section titled “Bool.is_not_eq”Bool.is_not_eq <- function<T: eq>(first: T, second: T) -> Bool#: <T: eq> fn(first: T, second: T) -> BoolBool.is_not_eq <- function(first, second)Whether two values differ by identical().
Bool.is_not_eq([1], [2])#> TRUE