-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathfunction.nix
56 lines (43 loc) · 1.12 KB
/
function.nix
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
53
54
55
56
with {
set = import ./set.nix;
types = import ./types.nix;
};
rec {
/* id :: a -> a
*/
id = x: x;
/* const :: a -> b -> a
*/
const = a: _: a;
/* compose :: (b -> c) -> (a -> b) -> (a -> c)
*/
compose = bc: ab: a: bc (ab a);
/* flip :: (a -> b -> c) -> b -> a -> c
*/
flip = f: b: a: f a b;
/* not :: (a -> bool) -> a -> bool
Inverts the boolean result of a function.
> function.not function.id true
false
*/
not = f: a: ! f a;
/* args :: (a -> b) -> set
*/
args = f:
if f ? __functor then f.__functionArgs or (args (f.__functor f))
else builtins.functionArgs f;
/* setArgs :: set -> (a -> b) -> (a -> b)
*/
setArgs = args: f: set.assign "__functionArgs" args (toSet f);
/* copyArgs :: (a -> b) -> (c -> b) -> (c -> b)
*/
copyArgs = src: dst: setArgs (args src) dst;
/* toSet :: (a -> b) -> set
Convert a lambda into a callable set, unless `f` already is one.
> function.toSet function.id // { foo = "bar"; }
{ __functor = «lambda»; foo = "bar"; }
*/
toSet = f: if types.lambda.check f then {
__functor = self: f;
} else f;
}