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:
parent
afdf1e0ed0
commit
b6089fb1e5
3 changed files with 15 additions and 0 deletions
|
@ -163,6 +163,19 @@ fn pure_builtins() -> Vec<Builtin> {
|
||||||
lists.into_iter().flatten().collect::<Vec<Value>>(),
|
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(
|
Builtin::new(
|
||||||
"div",
|
"div",
|
||||||
&[false, false],
|
&[false, false],
|
||||||
|
|
1
tvix/eval/src/tests/tvix_tests/eval-okay-concatmap.exp
Normal file
1
tvix/eval/src/tests/tvix_tests/eval-okay-concatmap.exp
Normal file
|
@ -0,0 +1 @@
|
||||||
|
[ "a" "z" "b" "z" ]
|
1
tvix/eval/src/tests/tvix_tests/eval-okay-concatmap.nix
Normal file
1
tvix/eval/src/tests/tvix_tests/eval-okay-concatmap.nix
Normal file
|
@ -0,0 +1 @@
|
||||||
|
(builtins.concatMap (x: [x] ++ ["z"]) ["a" "b"])
|
Loading…
Reference in a new issue