30 isFunction = builtins.isFunction;
31 isFunctor = f: f ? __functor;
32 isCallable = lib.isFunction;
34 # functor: f -> functor
37 else { __functor = _: f; };
40 if isFunction x then x
41 else if isFunctor x then toFunction (x.__functor x)
44 # foldr': (a -> b -> c) -> list -> iv
45 # foldr' f [a, b, c] d == f a (f b (f c d))
47 foldl' (f: b: c: f (op b c)) I ls iv;
49 ifElse = cond: then': else':
50 if cond then then' else else';
52 optionalRef = cond: sth: ifElse cond sth null;
55 if isAttrs sth then optionalAttrs cond sth
56 else if isInt sth then ifElse cond sth 0
57 else if isString sth then optionalString cond sth
58 else if isBool sth then ifElse cond sth false
59 else if isList sth then optionals cond sth
60 else if isFloat sth then ifElse cond sth 0.0
61 else if isFunction sth then optionalRef cond sth
62 else if isPath sth then optionalRef cond sth
63 else throw "unsupported result type";