mirror of
https://github.com/nushell/nu_scripts.git
synced 2024-08-17 01:10:36 +03:00
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:
parent
9d21cd5cd3
commit
20a297be73
4
stdlib-candidate/README.md
Normal file
4
stdlib-candidate/README.md
Normal 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
16
stdlib-candidate/str.nu
Normal 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
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user