From 7470fee507f49a7b26dd6ecfb262cc4e0da73f18 Mon Sep 17 00:00:00 2001 From: s-ol Date: Sat, 5 Feb 2022 13:20:36 +0100 Subject: lib: test and extend string module --- alv-lib/string.moon | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) (limited to 'alv-lib') diff --git a/alv-lib/string.moon b/alv-lib/string.moon index 7508e8d..e4b007c 100644 --- a/alv-lib/string.moon +++ b/alv-lib/string.moon @@ -1,4 +1,4 @@ -import PureOp, Constant, Input, T, any from require 'alv.base' +import PureOp, Constant, Input, T, Array, any from require 'alv.base' str = Constant.meta meta: @@ -8,7 +8,35 @@ str = Constant.meta value: class extends PureOp pattern: any!\rep 1, nil type: T.str - tick: => @out\set table.concat [tostring i! for i in *@inputs] + tick: => + strings = [i\type!\pp i!, true for i in *@inputs] + @out\set table.concat strings + +join = Constant.meta + meta: + name: 'join' + summary: "Concatenate/stringify values (with separator)" + examples: { '(join separator v1 [v2…])' } + value: class extends PureOp + pattern: any.str + any!\rep 1, nil + type: T.str + tick: => + strings = [i\type!\pp i!, true for i in *@inputs[2]] + @out\set table.concat strings, @inputs[1]! + +str_arr = any ((typ) -> typ.__class == Array and typ.type == T.str), "str[]" +concat = Constant.meta + meta: + name: 'concat' + summary: "Concatenate string arrays." + examples: { '(concat [separator] parts)' } + value: class extends PureOp + pattern: -any.str + str_arr + type: T.str + + tick: => + { separator, parts } = @unwrap_all! + @out\set table.concat parts, separator Constant.meta meta: @@ -17,3 +45,5 @@ Constant.meta value: :str, '..': str + :join + :concat -- cgit v1.2.3