2024-08-19 13:58:12 +00:00
|
|
|
lib:
|
2024-06-28 14:48:26 +00:00
|
|
|
rec {
|
|
|
|
# Ternary operator
|
|
|
|
# Exaample:
|
|
|
|
# tern false 1 2 => 2
|
|
|
|
# tern true 1 2 => 1
|
|
|
|
tern = pred: x: y: if pred then x else y;
|
|
|
|
|
|
|
|
# Right-associate and chain following single-operand functions
|
|
|
|
# Example:
|
|
|
|
# right f g h 1 => f(g(h(1)))
|
2024-08-19 13:58:12 +00:00
|
|
|
right = f: g: tern (lib.isFunction g)
|
2024-06-28 14:48:26 +00:00
|
|
|
(right (x: f (g (x))))
|
|
|
|
(f (g));
|
|
|
|
}
|