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-10T02·11-0400
committerclbot <clbot@tvl.fyi>2022-10-10T17·42+0000
commit8190046190dcce2844387729d0dbce6e5248ce41 (patch)
tree2fe5458f9393bfb0780cd9ee0145e876af052d0d /tvix/eval/src/builtins/mod.rs
parentb0547ccfa5e74cf21e813cd18f64ef62f1bf3734 (diff)
feat(tvix/eval): Implement builtins.elem r/5080
Change-Id: Id99c1d33f87ad9866990d3483d3531e9e48f861f
Reviewed-on: https://cl.tvl.fyi/c/depot/+/6916
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.rs8
1 files changed, 8 insertions, 0 deletions
diff --git a/tvix/eval/src/builtins/mod.rs b/tvix/eval/src/builtins/mod.rs
index 5819796236cd..8929d91cc9c6 100644
--- a/tvix/eval/src/builtins/mod.rs
+++ b/tvix/eval/src/builtins/mod.rs
@@ -174,6 +174,14 @@ fn pure_builtins() -> Vec<Builtin> {
             &[false, false],
             |args: Vec<Value>, vm: &mut VM| arithmetic_op!(&*args[0].force(vm)?, &*args[1].force(vm)?, /),
         ),
+        Builtin::new("elem", &[true, true], |args: Vec<Value>, vm: &mut VM| {
+            for val in args[1].to_list()? {
+                if val.nix_eq(&args[0], vm)? {
+                    return Ok(true.into());
+                }
+            }
+            Ok(false.into())
+        }),
         Builtin::new("elemAt", &[true, true], |args: Vec<Value>, _: &mut VM| {
             let xs = args[0].to_list()?;
             let i = args[1].as_int()?;