24 lines
484 B
Nix
24 lines
484 B
Nix
final: prev:
|
|
let
|
|
inherit (prev) isFunction mkMerge mkIf;
|
|
in
|
|
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)))
|
|
right = f: g: tern (isFunction g)
|
|
(right (x: f (g (x))))
|
|
(f (g));
|
|
|
|
mkIfElse = predicate: yes: no: mkMerge [
|
|
(mkIf predicate yes)
|
|
(mkIf (!predicate) no)
|
|
];
|
|
}
|