about summary refs log tree commit diff
path: root/tvix/eval/src/builtins/mod.rs
diff options
context:
space:
mode:
authorGriffin Smith <root@gws.fyi>2022-10-08T19·20-0400
committerclbot <clbot@tvl.fyi>2022-10-10T13·54+0000
commit0e97555644f54bf6991b5d44ff297b6343dbc7e0 (patch)
tree6404cbf46dcd36882f559485539c6ac43fe817b8 /tvix/eval/src/builtins/mod.rs
parentb6089fb1e516f967bc3f24e9a65c196bed0a9659 (diff)
feat(tvix/eval): Implement builtins.genList r/5075
Change-Id: Iabe28656229f508226b244d81382e517961eb3cf
Reviewed-on: https://cl.tvl.fyi/c/depot/+/6901
Autosubmit: grfn <grfn@gws.fyi>
Tested-by: BuildkiteCI
Reviewed-by: tazjin <tazjin@tvl.su>
Diffstat (limited to 'tvix/eval/src/builtins/mod.rs')
-rw-r--r--tvix/eval/src/builtins/mod.rs11
1 files changed, 11 insertions, 0 deletions
diff --git a/tvix/eval/src/builtins/mod.rs b/tvix/eval/src/builtins/mod.rs
index e047ef599b2d..93b04bb37b44 100644
--- a/tvix/eval/src/builtins/mod.rs
+++ b/tvix/eval/src/builtins/mod.rs
@@ -222,6 +222,17 @@ fn pure_builtins() -> Vec<Builtin> {
                 .map(|list| Value::List(NixList::from(list)))
                 .map_err(Into::into)
         }),
+        Builtin::new("genList", &[true, true], |args: Vec<Value>, vm: &mut VM| {
+            let len = args[1].as_int()?;
+            (0..len)
+                .map(|i| {
+                    vm.push(i.into());
+                    vm.call_value(&args[0])
+                })
+                .collect::<Result<Vec<Value>, _>>()
+                .map(|list| Value::List(NixList::from(list)))
+                .map_err(Into::into)
+        }),
         Builtin::new("getAttr", &[true, true], |args: Vec<Value>, _: &mut VM| {
             let k = args[0].to_str()?;
             let xs = args[1].to_attrs()?;