mirror of
https://github.com/nushell/nushell.git
synced 2025-08-09 20:57:49 +02:00
add std repeat
command to replace "foo" * 3
(#10339)
related to - https://github.com/nushell/nushell/issues/10233 - https://github.com/nushell/nushell/pull/10293 - https://github.com/nushell/nushell/pull/10292 inspired by @kubouch # Description this PR adds a `repeat` command to the standard library # User-Facing Changes a new `repeat` command in `std` ```nushell repeat anything a bunch of times, yielding a list of *n* times the input # Examples repeat a string > "foo" | std repeat 3 | str join "foofoofoo" Usage: > repeat <n> Flags: -h, --help - Display the help message for this command Parameters: n <int>: the number of repetitions, must be positive Input/output types: ╭───┬───────┬───────────╮ │ # │ input │ output │ ├───┼───────┼───────────┤ │ 0 │ any │ list<any> │ ╰───┴───────┴───────────╯ ``` # Tests + Formatting a new test called `repeat_things` in `test_std.nu` # After Submitting
This commit is contained in:
@ -44,3 +44,14 @@ def path_add [] {
|
||||
def banner [] {
|
||||
std assert ((std banner | lines | length) == 15)
|
||||
}
|
||||
|
||||
#[test]
|
||||
def repeat_things [] {
|
||||
std assert error { "foo" | std repeat -1 }
|
||||
|
||||
for x in ["foo", [1 2], {a: 1}] {
|
||||
std assert equal ($x | std repeat 0) []
|
||||
std assert equal ($x | std repeat 1) [$x]
|
||||
std assert equal ($x | std repeat 2) [$x $x]
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user