brewery
notashelf /
760094a2b70a3abacac0d386b19bd7274244782f

nixir

public

Import-resolving Nix IR plugin

Star0tarball
clone
ssh://git@git.notashelf.dev:33/notashelf/nixir.git
tests/benchmark/medium.nixNix75 lines1.3 KB
1
let
2
  # Recursive factorial
3
  factorial = n:
4
    if n <= 1
5
    then 1
6
    else n * factorial (n - 1);
7
8
  # Fibonacci sequence generator
9
  fib = n:
10
    if n <= 1
11
    then n
12
    else fib (n - 1) + fib (n - 2);
13
14
  # List concatenation test
15
  range = start: end:
16
    if start >= end
17
    then []
18
    else [start] ++ range (start + 1) end;
19
20
  # Curried function application
21
  add = x: y: x + y;
22
  add5 = add 5;
23
24
  # Complex computation
25
  compute = x: y: let
26
    a = x * 2;
27
    b = y + 10;
28
    c = a * b;
29
  in
30
    c / 2;
31
32
  # Data structures
33
  numbers = range 1 11;
34
35
  # Nested attribute operations
36
  base = {
37
    config = {
38
      enable = true;
39
      value = 42;
40
    };
41
    data = {
42
      items = [1 2 3];
43
    };
44
  };
45
46
  extended =
47
    base
48
    // {
49
      config =
50
        base.config
51
        // {
52
          extra = "test";
53
          multiplied = base.config.value * 2;
54
        };
55
      computed = base.config.value + 100;
56
    };
57
58
  # Recursive attrset with selections
59
  recursive = rec {
60
    x = 10;
61
    y = x * 2;
62
    z = y + x;
63
    result = z * 3;
64
    final = result + x;
65
  };
66
in {
67
  fact5 = factorial 5;
68
  fib7 = fib 7;
69
  sum15 = add5 10;
70
  computed = compute 10 20;
71
  inherit numbers extended;
72
  deepValue = extended.config.multiplied;
73
  recursiveResult = recursive.result;
74
  recursiveFinal = recursive.final;
75
}