about summary refs log tree commit diff
path: root/tvix/eval/src/builtins/mod.rs
diff options
context:
space:
mode:
authorGriffin Smith <root@gws.fyi>2022-10-09T17·09-0400
committergrfn <grfn@gws.fyi>2022-10-10T20·23+0000
commit66a35de3b67dd441185b7badaf559c8a25ab9967 (patch)
tree4ca9d3d07252e679f2d22293eda5c229e74b9d24 /tvix/eval/src/builtins/mod.rs
parent41ddc37725a59b4af0f7043a7fd66b3fe48f935d (diff)
feat(tvix/eval): Implement builtins.concatStringsSep r/5084
Change-Id: I6e46bcdbf3b5258b60edb017709fee577eb8ec74
Reviewed-on: https://cl.tvl.fyi/c/depot/+/6907
Reviewed-by: tazjin <tazjin@tvl.su>
Tested-by: BuildkiteCI
Diffstat (limited to 'tvix/eval/src/builtins/mod.rs')
-rw-r--r--tvix/eval/src/builtins/mod.rs16
1 files changed, 16 insertions, 0 deletions
diff --git a/tvix/eval/src/builtins/mod.rs b/tvix/eval/src/builtins/mod.rs
index 8929d91cc9c6..08b8299e4803 100644
--- a/tvix/eval/src/builtins/mod.rs
+++ b/tvix/eval/src/builtins/mod.rs
@@ -170,6 +170,22 @@ fn pure_builtins() -> Vec<Builtin> {
             },
         ),
         Builtin::new(
+            "concatStringsSep",
+            &[true, true],
+            |args: Vec<Value>, vm: &mut VM| {
+                let separator = args[0].to_str()?;
+                let list = args[1].to_list()?;
+                let mut res = String::new();
+                for (i, val) in list.into_iter().enumerate() {
+                    if i != 0 {
+                        res.push_str(&separator);
+                    }
+                    res.push_str(&val.force(vm)?.coerce_to_string(CoercionKind::Weak, vm)?);
+                }
+                Ok(res.into())
+            },
+        ),
+        Builtin::new(
             "div",
             &[false, false],
             |args: Vec<Value>, vm: &mut VM| arithmetic_op!(&*args[0].force(vm)?, &*args[1].force(vm)?, /),