feat(tvix/eval): Implement builtins.intersectAttrs
Change-Id: Iaba9bcfa19f283cd0c1931be2f211e2528a1a940 Reviewed-on: https://cl.tvl.fyi/c/depot/+/6998 Tested-by: BuildkiteCI Reviewed-by: tazjin <tazjin@tvl.su> Reviewed-by: kanepyork <rikingcoding@gmail.com>
This commit is contained in:
parent
03a3189a3d
commit
3f45f6191d
3 changed files with 19 additions and 0 deletions
|
@ -309,6 +309,21 @@ fn pure_builtins() -> Vec<Builtin> {
|
|||
None => Err(ErrorKind::IndexOutOfBounds { index: 0 }),
|
||||
}
|
||||
}),
|
||||
Builtin::new(
|
||||
"intersectAttrs",
|
||||
&[true, true],
|
||||
|args: Vec<Value>, _: &mut VM| {
|
||||
let mut res = BTreeMap::new();
|
||||
let attrs1 = args[0].to_attrs()?;
|
||||
let attrs2 = args[1].to_attrs()?;
|
||||
for (k, v) in attrs2.iter() {
|
||||
if attrs1.contains(k) {
|
||||
res.insert(k.clone(), v.clone());
|
||||
}
|
||||
}
|
||||
Ok(Value::attrs(NixAttrs::from_map(res)))
|
||||
},
|
||||
),
|
||||
// For `is*` predicates we force manually, as Value::force also unwraps any Thunks
|
||||
Builtin::new("isAttrs", &[false], |args: Vec<Value>, vm: &mut VM| {
|
||||
let value = args[0].force(vm)?;
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
{ a = 100; b = 200; }
|
|
@ -0,0 +1,3 @@
|
|||
builtins.intersectAttrs
|
||||
{ a = 1; b = 2; c = 3; }
|
||||
{ a = 100; b = 200; d = 5; }
|
Loading…
Reference in a new issue