labs/lib/src/bools/default.nix

49 lines
1.3 KiB
Nix
Raw Normal View History

2024-06-01 11:00:53 +00:00
lib: {
bools = {
into = {
2024-06-03 09:57:13 +00:00
## Convert a boolean value into a string.
##
## @type Bool -> String
2024-06-22 17:58:44 +00:00
string = value: if value then "true" else "false";
2024-06-03 09:57:13 +00:00
## Convert a boolean into either the string "yes" or "no".
##
## @type Bool -> String
2024-06-22 17:58:44 +00:00
yesno = value: if value then "yes" else "no";
2024-06-01 11:00:53 +00:00
};
## Choose between two values based on a condition. When true, the first value
## is returned, otherwise the second value is returned.
##
## @type Bool -> a -> b -> a | b
2024-06-22 17:58:44 +00:00
when =
condition: x: y:
if condition then x else y;
2024-06-01 11:00:53 +00:00
## Perform a logical AND operation on two values.
##
## @type Bool -> Bool -> Bool
and = a: b: a && b;
## Perform a logical AND operation on two functions being applied to a value.
##
## @type (a -> Bool) -> (a -> Bool) -> a -> Bool
2024-06-22 17:58:44 +00:00
and' = f: g: (x: (f x) && (g x));
2024-06-01 11:00:53 +00:00
## Perform a logical OR operation on two values.
##
## @type Bool -> Bool -> Bool
or = a: b: a || b;
## Perform a logical OR operation on two functions being applied to a value.
##
## @type (a -> Bool) -> (a -> Bool) -> a -> Bool
2024-06-22 17:58:44 +00:00
or' = f: g: (x: (f x) || (g x));
2024-06-01 11:00:53 +00:00
## Perform a logical NOT operation on a value.
##
## @type Bool -> Bool
not = a: !a;
};
}