From 677af097ae444498e10339f9ef0ecd86659c52e0 Mon Sep 17 00:00:00 2001 From: Darren Schroeder <343840+fdncred@users.noreply.github.com> Date: Fri, 29 Jan 2021 09:52:07 -0600 Subject: [PATCH] added the ability to print tables as arguments to print3 --- stdlib_candidate/print.nu | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/stdlib_candidate/print.nu b/stdlib_candidate/print.nu index 5da3340..4612ae6 100644 --- a/stdlib_candidate/print.nu +++ b/stdlib_candidate/print.nu @@ -40,3 +40,38 @@ def print2 [ echo $rest | str from | str collect $separator } } + +def print3 [ + --separator(-s):any # Optional separator (not yet flagged as optional?) + --flat(-f) # If tables are found, flatten them + ...rest # All of the parameters + ] { + let sep_empty = $(= $separator | empty?) + let num_of_rest = $(echo $rest | count) + echo $rest | each --numbered { + if $sep_empty { + if $(echo $it.item | count) > 1 && $flat { + let flatter = $(echo $it.item | flatten | str from | str collect) + build-string $flatter + } { + build-string $it.item + } + } { + if $num_of_rest > $(= $it.index + 1) { + if $(echo $it.item | count) > 1 && $flat { + let flatter = $(echo $it.item | flatten | str from | str collect $separator) + build-string $flatter $separator + } { + build-string $it.item $separator + } + } { + if $(echo $it.item | count) > 1 && $flat { + let flatter = $(echo $it.item | flatten | str from | str collect $separator) + build-string $flatter + } { + build-string $it.item + } + } + } + } | str collect +}