about summary refs log tree commit diff
path: root/tvix/eval/src/builtins/mod.rs
diff options
context:
space:
mode:
Diffstat (limited to 'tvix/eval/src/builtins/mod.rs')
-rw-r--r--tvix/eval/src/builtins/mod.rs12
1 files changed, 12 insertions, 0 deletions
diff --git a/tvix/eval/src/builtins/mod.rs b/tvix/eval/src/builtins/mod.rs
index 3598ac71f7db..33abfe492d10 100644
--- a/tvix/eval/src/builtins/mod.rs
+++ b/tvix/eval/src/builtins/mod.rs
@@ -51,6 +51,18 @@ fn pure_builtins() -> Vec<Builtin> {
                 args.pop().unwrap().to_str()?.as_str().to_owned(),
             ));
         }),
+        Builtin::new("attrNames", 1, |args, vm| {
+            force!(vm, &args[0], value, {
+                let xs = value.to_attrs()?;
+                let mut output = Vec::with_capacity(xs.len());
+
+                for (key, _val) in xs.iter() {
+                    output.push(Value::String(key.clone()));
+                }
+
+                Ok(Value::List(NixList::construct(output.len(), output)))
+            })
+        }),
         Builtin::new("catAttrs", 2, |mut args, _| {
             let list = args.pop().unwrap().to_list()?;
             let key = args.pop().unwrap().to_str()?;