diff options
| author | h7x4 <h7x4@nani.wtf> | 2023-10-17 01:12:49 +0200 |
|---|---|---|
| committer | h7x4 <h7x4@nani.wtf> | 2023-10-31 20:25:41 +0100 |
| commit | 206d20426cb2959aab8cc3cfc8e62aa68bc7b52f (patch) | |
| tree | 9e16017e21242d993fddf9ec37ecf02ac9e8f7e6 /lib/strings.nix | |
| parent | Merge pull request #261077 from NixOS/php/bump/8-3-0RC4 (diff) | |
| download | nixpkgs-206d20426cb2959aab8cc3cfc8e62aa68bc7b52f.tar.gz | |
lib.strings: add `replicate`
`strings.replicate` returns n copies of a string, concatenated into a new
string
Co-authored-by: Silvan Mosberger <github@infinisil.com>
Diffstat (limited to 'lib/strings.nix')
| -rw-r--r-- | lib/strings.nix | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/lib/strings.nix b/lib/strings.nix index 628669d86bbd..695aaaacd348 100644 --- a/lib/strings.nix +++ b/lib/strings.nix @@ -144,6 +144,20 @@ rec { */ concatLines = concatMapStrings (s: s + "\n"); + /* + Replicate a string n times, + and concatenate the parts into a new string. + + Type: replicate :: int -> string -> string + + Example: + replicate 3 "v" + => "vvv" + replicate 5 "hello" + => "hellohellohellohellohello" + */ + replicate = n: s: concatStrings (lib.lists.replicate n s); + /* Construct a Unix-style, colon-separated search path consisting of the given `subDir` appended to each of the given paths. |
