about summary refs log tree commit diff
path: root/tvix/eval/src/builtins/mod.rs
diff options
context:
space:
mode:
authorWilliam Carroll <wpcarro@gmail.com>2022-09-06T21·13-0700
committerclbot <clbot@tvl.fyi>2022-09-19T16·18+0000
commit059f4b964fc957692063db27bccf70e65e330c77 (patch)
treed9348cf5122ad244f1baa9d9da5cc34160d1550d /tvix/eval/src/builtins/mod.rs
parent5b165e73186f01a6dec11a804ab6921673806d82 (diff)
feat(tvix/eval): Support builtins.hasAttr r/4927
See unit tests for examples :)

Change-Id: Ieec51d780a7762cc455ca03a9dc1648a0711924a
Reviewed-on: https://cl.tvl.fyi/c/depot/+/6553
Reviewed-by: wpcarro <wpcarro@gmail.com>
Autosubmit: wpcarro <wpcarro@gmail.com>
Reviewed-by: sterni <sternenseemann@systemli.org>
Tested-by: BuildkiteCI
Diffstat (limited to 'tvix/eval/src/builtins/mod.rs')
-rw-r--r--tvix/eval/src/builtins/mod.rs6
1 files changed, 6 insertions, 0 deletions
diff --git a/tvix/eval/src/builtins/mod.rs b/tvix/eval/src/builtins/mod.rs
index a5ca2114e1f7..f6af16f96f9d 100644
--- a/tvix/eval/src/builtins/mod.rs
+++ b/tvix/eval/src/builtins/mod.rs
@@ -134,6 +134,12 @@ fn pure_builtins() -> Vec<Builtin> {
         Builtin::new("length", &[true], |args, _| {
             Ok(Value::Integer(args[0].to_list()?.len() as i64))
         }),
+        Builtin::new("hasAttr", &[true, true], |args, _| {
+            let k = args[0].to_str()?;
+            let xs = args[1].to_attrs()?;
+
+            Ok(Value::Bool(xs.contains(k.as_str())))
+        }),
         Builtin::new("head", &[true], |args, _| match args[0].to_list()?.get(0) {
             Some(x) => Ok(x.clone()),
             None => Err(ErrorKind::IndexOutOfBounds { index: 0 }),