feat(nix/eval): Implement builtins.groupBy
Change-Id: I3e0aa017a7100cbeb86d2e5747471b36affcc102 Reviewed-on: https://cl.tvl.fyi/c/depot/+/7038 Autosubmit: grfn <grfn@gws.fyi> Reviewed-by: tazjin <tazjin@tvl.su> Tested-by: BuildkiteCI
This commit is contained in:
parent
dfa4c4847c
commit
e2f0967d3f
3 changed files with 34 additions and 0 deletions
|
@ -323,6 +323,17 @@ fn pure_builtins() -> Vec<Builtin> {
|
|||
}),
|
||||
}
|
||||
}),
|
||||
Builtin::new("groupBy", &[true, true], |args: Vec<Value>, vm: &mut VM| {
|
||||
let mut res: BTreeMap<NixString, Value> = BTreeMap::new();
|
||||
for val in args[1].to_list()? {
|
||||
let key = vm.call_with(&args[0], [val.clone()])?.force(vm)?.to_str()?;
|
||||
res.entry(key)
|
||||
.or_insert_with(|| Value::List(NixList::new()))
|
||||
.as_list_mut()?
|
||||
.push(val);
|
||||
}
|
||||
Ok(Value::attrs(NixAttrs::from_map(res)))
|
||||
}),
|
||||
Builtin::new("hasAttr", &[true, true], |args: Vec<Value>, _: &mut VM| {
|
||||
let k = args[0].to_str()?;
|
||||
let xs = args[1].to_attrs()?;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue