about summary refs log tree commit diff
path: root/tvix/eval/src/builtins/mod.rs
diff options
context:
space:
mode:
authorVincent Ambo <mail@tazj.in>2022-10-02T16·41+0300
committertazjin <tazjin@tvl.su>2022-10-03T07·53+0000
commit939b2194fe6b0159191892d7bfc7ff527c1b0371 (patch)
tree1be59768909331bd67e29b7e98a54abaaa0330d6 /tvix/eval/src/builtins/mod.rs
parent3c9520a4e56e09c59b007b2965372c7173b4e40d (diff)
feat(tvix/eval): implement builtins.concatLists r/5022
Concatenates (but not flattens) a list of lists.

Change-Id: I692e0b3e7b5a5ff93d5768d3a27849b432ec5747
Reviewed-on: https://cl.tvl.fyi/c/depot/+/6843
Autosubmit: tazjin <tazjin@tvl.su>
Reviewed-by: sterni <sternenseemann@systemli.org>
Tested-by: BuildkiteCI
Diffstat (limited to 'tvix/eval/src/builtins/mod.rs')
-rw-r--r--tvix/eval/src/builtins/mod.rs14
1 files changed, 14 insertions, 0 deletions
diff --git a/tvix/eval/src/builtins/mod.rs b/tvix/eval/src/builtins/mod.rs
index 45630819e124..94a035c2ece7 100644
--- a/tvix/eval/src/builtins/mod.rs
+++ b/tvix/eval/src/builtins/mod.rs
@@ -116,6 +116,20 @@ fn pure_builtins() -> Vec<Builtin> {
                 std::cmp::Ordering::Greater => Ok(Value::Integer(1)),
             }
         }),
+        Builtin::new("concatLists", &[true], |args, vm| {
+            let list = args[0].to_list()?;
+            let lists = list
+                .into_iter()
+                .map(|elem| {
+                    let value = elem.force(vm)?;
+                    value.to_list()
+                })
+                .collect::<Result<Vec<NixList>, ErrorKind>>()?;
+
+            Ok(Value::List(NixList::from(
+                lists.into_iter().flatten().collect::<Vec<Value>>(),
+            )))
+        }),
         Builtin::new(
             "div",
             &[false, false],