about summary refs log tree commit diff
path: root/users/sterni/nix/fun/default.nix
blob: 6b3541ed4c65759720a19feda4ac662b3bf62421 (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
53
54
55
56
57
58
59
{ depot, lib, ... }:

let

  inherit (lib)
    id
    ;

  # Simple function composition,
  # application is right to left.
  rl = f1: f2:
    (x: f1 (f2 x));

  # Compose a list of functions,
  # application is right to left.
  rls = fs:
    builtins.foldl' (fOut: f: lr f fOut) id fs;

  # Simple function composition,
  # application is left to right.
  lr = f1: f2:
    (x: f2 (f1 x));

  # Compose a list of functions,
  # application is left to right
  lrs = x: fs:
    builtins.foldl' (v: f: f v) x fs;

  # Warning: cursed function
  #
  # Check if a function has an attribute
  # set pattern with an ellipsis as its argument.
  #
  # s/o to puck for discovering that you could use
  # builtins.toXML to introspect functions more than
  # you should be able to in Nix.
  hasEllipsis = f:
    builtins.isFunction f &&
    builtins.match ".*<attrspat ellipsis=\"1\">.*"
      (builtins.toXML f) != null;

in

{
  inherit (lib)
    fix
    flip
    const
    ;

  inherit
    id
    rl
    rls
    lr
    lrs
    hasEllipsis
    ;
}