From 20a297be73665c31f9e9749fe3aff1801a5520bc Mon Sep 17 00:00:00 2001 From: Sam Vente Date: Sun, 1 Oct 2023 00:13:46 +0200 Subject: [PATCH] Add `str append` to stdlib-candidate (#626) As discussed in https://github.com/nushell/nushell/issues/10486 I've added an stdlib-candidate folder where we can add scripts that might want to be in std-lib at some point. Currently it only contains `str append` and `str prepend` which work about how you'd expect. Thanks to @amtoine for writing the initial function. I added a default branch that just returns the input unaltered so it can be used more easily in the middle of a pipe. --- stdlib-candidate/README.md | 4 ++++ stdlib-candidate/str.nu | 16 ++++++++++++++++ 2 files changed, 20 insertions(+) create mode 100644 stdlib-candidate/README.md create mode 100644 stdlib-candidate/str.nu diff --git a/stdlib-candidate/README.md b/stdlib-candidate/README.md new file mode 100644 index 0000000..4c84971 --- /dev/null +++ b/stdlib-candidate/README.md @@ -0,0 +1,4 @@ +# std-lib candidate + +This folder is where we can add scripts that might want to be in std-lib at some point. It can serve both as a holding place for scripts that are waiting on nushell changes, as well as a place to develop and discuss such scripts. + diff --git a/stdlib-candidate/str.nu b/stdlib-candidate/str.nu new file mode 100644 index 0000000..fe5a8d4 --- /dev/null +++ b/stdlib-candidate/str.nu @@ -0,0 +1,16 @@ +def "str append" [tail: string]: [string -> string, list -> list] { + let input = $in + match ($input | describe | str replace --regex '<.*' '') { + "string" => { $input ++ $tail }, + "list" => { $input | each {|el| $el ++ $tail} }, + _ => $input + } +} +def "str prepend" [head: string]: [string -> string, list -> list] { + let input = $in + match ($input | describe | str replace --regex '<.*' '') { + "string" => { $head ++ $input }, + "list" => { $input | each {|el| $head ++ $el } }, + _ => $input + } +}