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-09T16·59-0400
committerclbot <clbot@tvl.fyi>2022-10-10T15·26+0000
commitba8ec1910bf2527eb290c128a04c23f42ec6a3bb (patch)
tree9dc58e5037ffe74ae041907ef2e92a6e7d44c0ab /tvix/eval/src/builtins/mod.rs
parent0e97555644f54bf6991b5d44ff297b6343dbc7e0 (diff)
feat(tvix/eval): Implement builtins.foldl' r/5076
Change-Id: Ibc97db4343cb3a1a1677f69fb6c3518c61978aad
Reviewed-on: https://cl.tvl.fyi/c/depot/+/6906
Autosubmit: grfn <grfn@gws.fyi>
Reviewed-by: tazjin <tazjin@tvl.su>
Tested-by: BuildkiteCI
Diffstat (limited to 'tvix/eval/src/builtins/mod.rs')
-rw-r--r--tvix/eval/src/builtins/mod.rs18
1 files changed, 18 insertions, 0 deletions
diff --git a/tvix/eval/src/builtins/mod.rs b/tvix/eval/src/builtins/mod.rs
index 93b04bb37b44..f32a29a20660 100644
--- a/tvix/eval/src/builtins/mod.rs
+++ b/tvix/eval/src/builtins/mod.rs
@@ -222,6 +222,24 @@ fn pure_builtins() -> Vec<Builtin> {
                 .map(|list| Value::List(NixList::from(list)))
                 .map_err(Into::into)
         }),
+        Builtin::new(
+            "foldl'",
+            &[true, false, true],
+            |mut args: Vec<Value>, vm: &mut VM| {
+                let list = args.pop().unwrap().to_list()?;
+                let mut res = args.pop().unwrap();
+                let op = args.pop().unwrap();
+                for val in list {
+                    val.force(vm)?;
+                    vm.push(val);
+                    vm.push(res);
+                    let partial = vm.call_value(&op)?;
+                    res = vm.call_value(&partial)?;
+                }
+
+                Ok(res)
+            },
+        ),
         Builtin::new("genList", &[true, true], |args: Vec<Value>, vm: &mut VM| {
             let len = args[1].as_int()?;
             (0..len)