feat(tvix/eval): Implement builtins.concatMap

Change-Id: I08bfd040a242aa43b64760c19f48a28303f206ac
Reviewed-on: https://cl.tvl.fyi/c/depot/+/6900
Autosubmit: grfn <grfn@gws.fyi>
Tested-by: BuildkiteCI
Reviewed-by: tazjin <tazjin@tvl.su>
This commit is contained in:
Griffin Smith 2022-10-08 15:12:32 -04:00 committed by clbot
parent afdf1e0ed0
commit b6089fb1e5
3 changed files with 15 additions and 0 deletions

View file

@ -163,6 +163,19 @@ fn pure_builtins() -> Vec<Builtin> {
lists.into_iter().flatten().collect::<Vec<Value>>(),
)))
}),
Builtin::new(
"concatMap",
&[true, true],
|args: Vec<Value>, vm: &mut VM| {
let list = args[1].to_list()?;
let mut res = Vec::new();
for val in list {
vm.push(val);
res.extend(vm.call_value(&args[0])?.force(vm)?.to_list()?);
}
Ok(Value::List(res.into()))
},
),
Builtin::new(
"div",
&[false, false],

View file

@ -0,0 +1 @@
[ "a" "z" "b" "z" ]

View file

@ -0,0 +1 @@
(builtins.concatMap (x: [x] ++ ["z"]) ["a" "b"])