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.
This commit is contained in:
Sam Vente 2023-10-01 00:13:46 +02:00 committed by GitHub
parent 9d21cd5cd3
commit 20a297be73
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 0 deletions

View File

@ -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.

16
stdlib-candidate/str.nu Normal file
View File

@ -0,0 +1,16 @@
def "str append" [tail: string]: [string -> string, list<string> -> list<string>] {
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<string> -> list<string>] {
let input = $in
match ($input | describe | str replace --regex '<.*' '') {
"string" => { $head ++ $input },
"list" => { $input | each {|el| $head ++ $el } },
_ => $input
}
}