diff options
-rw-r--r-- | tvix/eval/src/builtins/mod.rs | 13 | ||||
-rw-r--r-- | tvix/eval/src/tests/nix_tests/eval-okay-mapattrs.exp (renamed from tvix/eval/src/tests/nix_tests/notyetpassing/eval-okay-mapattrs.exp) | 0 | ||||
-rw-r--r-- | tvix/eval/src/tests/nix_tests/eval-okay-mapattrs.nix (renamed from tvix/eval/src/tests/nix_tests/notyetpassing/eval-okay-mapattrs.nix) | 0 | ||||
-rw-r--r-- | tvix/eval/src/value/attrs.rs | 10 |
4 files changed, 23 insertions, 0 deletions
diff --git a/tvix/eval/src/builtins/mod.rs b/tvix/eval/src/builtins/mod.rs index d6b52e20a2a3..e7eb4e8bf953 100644 --- a/tvix/eval/src/builtins/mod.rs +++ b/tvix/eval/src/builtins/mod.rs @@ -436,6 +436,19 @@ fn pure_builtins() -> Vec<Builtin> { .map_err(Into::into) }), Builtin::new( + "mapAttrs", + &[true, true], + |args: Vec<Value>, vm: &mut VM| { + let attrs = args[1].to_attrs()?; + let mut res = BTreeMap::new(); + for (key, value) in attrs.as_ref() { + let value = vm.call_with(&args[0], [key.clone().into(), value.clone()])?; + res.insert(key.clone(), value); + } + Ok(Value::attrs(NixAttrs::from_map(res))) + }, + ), + Builtin::new( "match", &[true, true], |mut args: Vec<Value>, _: &mut VM| { diff --git a/tvix/eval/src/tests/nix_tests/notyetpassing/eval-okay-mapattrs.exp b/tvix/eval/src/tests/nix_tests/eval-okay-mapattrs.exp index 3f113f17bab1..3f113f17bab1 100644 --- a/tvix/eval/src/tests/nix_tests/notyetpassing/eval-okay-mapattrs.exp +++ b/tvix/eval/src/tests/nix_tests/eval-okay-mapattrs.exp diff --git a/tvix/eval/src/tests/nix_tests/notyetpassing/eval-okay-mapattrs.nix b/tvix/eval/src/tests/nix_tests/eval-okay-mapattrs.nix index f075b6275e5a..f075b6275e5a 100644 --- a/tvix/eval/src/tests/nix_tests/notyetpassing/eval-okay-mapattrs.nix +++ b/tvix/eval/src/tests/nix_tests/eval-okay-mapattrs.nix diff --git a/tvix/eval/src/value/attrs.rs b/tvix/eval/src/value/attrs.rs index 17c7b422cb0d..c0f82b921449 100644 --- a/tvix/eval/src/value/attrs.rs +++ b/tvix/eval/src/value/attrs.rs @@ -517,3 +517,13 @@ impl<'a> Iterator for Keys<'a> { } } } + +impl<'a> IntoIterator for &'a NixAttrs { + type Item = (&'a NixString, &'a Value); + + type IntoIter = Iter<KeyValue<'a>>; + + fn into_iter(self) -> Self::IntoIter { + self.iter() + } +} |