about summary refs log tree commit diff
path: root/tvix/eval/src/builtins/mod.rs
diff options
context:
space:
mode:
authorJames Landrein <james.landrein@gmail.com>2022-10-14T11·49+0200
committerclbot <clbot@tvl.fyi>2022-10-16T22·51+0000
commit5ee2258692da4d5c65b22416fcc3ec87db013ff8 (patch)
tree614235426ed233a7e080f2337f87174a219781f6 /tvix/eval/src/builtins/mod.rs
parent4dcb8f38c2e442b6433b21b8a7de303736a04568 (diff)
feat(tvix/eval): implement builtins.partition r/5148
Change-Id: I8b591f3057c68c1542046fc5a771973f2238c9df
Reviewed-on: https://cl.tvl.fyi/c/depot/+/7020
Autosubmit: j4m3s <james.landrein@gmail.com>
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.rs25
1 files changed, 25 insertions, 0 deletions
diff --git a/tvix/eval/src/builtins/mod.rs b/tvix/eval/src/builtins/mod.rs
index 03466af65f89..e9ad4a8ee82e 100644
--- a/tvix/eval/src/builtins/mod.rs
+++ b/tvix/eval/src/builtins/mod.rs
@@ -447,6 +447,31 @@ fn pure_builtins() -> Vec<Builtin> {
             ]))))
         }),
         Builtin::new(
+            "partition",
+            &[true, true],
+            |args: Vec<Value>, vm: &mut VM| {
+                let mut right: Vec<Value> = vec![];
+                let mut wrong: Vec<Value> = vec![];
+
+                let list: NixList = args[1].to_list()?;
+                for elem in list.into_iter() {
+                    let result = vm.call_with(&args[0], [elem.clone()])?;
+
+                    if result.force(vm)?.as_bool()? {
+                        right.push(elem);
+                    } else {
+                        wrong.push(elem);
+                    };
+                }
+
+                let mut res: BTreeMap<NixString, Value> = BTreeMap::new();
+                res.insert("right".into(), Value::List(right.into()));
+                res.insert("wrong".into(), Value::List(wrong.into()));
+
+                Ok(Value::attrs(NixAttrs::from_map(res)))
+            },
+        ),
+        Builtin::new(
             "removeAttrs",
             &[true, true],
             |args: Vec<Value>, _: &mut VM| {