blob: a9fe3c673532fda1a787c102f3d35f47831d1f98 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
{ depot, ... }:
let
inherit (depot.nix)
yants
;
# we must avoid evaluating any of the sublists
# as they may contain conditions that throw
condition = yants.restrict "condition"
(ls: builtins.length ls == 2)
(yants.list yants.any);
/* cond :: [ [ bool any ] ] -> any
*
* Like the common lisp macro: takes a list
* of two elemented lists whose first element
* is a boolean. The second element of the
* first list that has true as its first
* element is returned.
*
* Example:
*
* cond [
* [ (builtins.isString true) 12 ]
* [ (3 == 2) 13 ]
* [ true 42 ]
* ]
*
* => 42
*/
cond = conds:
if builtins.length conds == 0
then builtins.throw "cond: exhausted all conditions"
else
let
c = condition (builtins.head conds);
in
if builtins.head c
then builtins.elemAt c 1
else cond (builtins.tail conds);
# TODO(sterni): condf or magic
# like <nixpkgs/pkgs/build-support/coq/extra-lib.nix>
in {
inherit
cond
;
}
|