diff options
author | Silvan Mosberger <contact@infinisil.com> | 2023-01-31 18:05:53 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-01-31 18:05:53 +0100 |
commit | 50e4dbf35b95fd2b96718b656ebcbc6f9fa3a4ab (patch) | |
tree | cc90137eb87bb1afc11293c88a86edfa2df75805 | |
parent | a743cf65d36af9633fe758092e54b0ba4f1f43e7 (diff) | |
parent | ed0b8c26f127525a9ee66f895bdc894cdaa5d685 (diff) |
Merge pull request #205557 from ncfavier/concatLines
lib/strings: add `concatLines`
-rw-r--r-- | lib/default.nix | 2 | ||||
-rw-r--r-- | lib/strings.nix | 11 | ||||
-rw-r--r-- | lib/tests/misc.nix | 5 |
3 files changed, 17 insertions, 1 deletions
diff --git a/lib/default.nix b/lib/default.nix index 8ce1de33f5dce..b1441c7281049 100644 --- a/lib/default.nix +++ b/lib/default.nix @@ -94,7 +94,7 @@ let subtractLists mutuallyExclusive groupBy groupBy'; inherit (self.strings) concatStrings concatMapStrings concatImapStrings intersperse concatStringsSep concatMapStringsSep - concatImapStringsSep makeSearchPath makeSearchPathOutput + concatImapStringsSep concatLines makeSearchPath makeSearchPathOutput makeLibraryPath makeBinPath optionalString hasInfix hasPrefix hasSuffix stringToCharacters stringAsChars escape escapeShellArg escapeShellArgs diff --git a/lib/strings.nix b/lib/strings.nix index 2188fcb1dbfd1..68d9309506625 100644 --- a/lib/strings.nix +++ b/lib/strings.nix @@ -128,6 +128,17 @@ rec { # List of input strings list: concatStringsSep sep (lib.imap1 f list); + /* Concatenate a list of strings, adding a newline at the end of each one. + Defined as `concatMapStrings (s: s + "\n")`. + + Type: concatLines :: [string] -> string + + Example: + concatLines [ "foo" "bar" ] + => "foo\nbar\n" + */ + concatLines = concatMapStrings (s: s + "\n"); + /* Construct a Unix-style, colon-separated search path consisting of the given `subDir` appended to each of the given paths. diff --git a/lib/tests/misc.nix b/lib/tests/misc.nix index faf2b96530c1c..c14bddb11a137 100644 --- a/lib/tests/misc.nix +++ b/lib/tests/misc.nix @@ -153,6 +153,11 @@ runTests { expected = "a,b,c"; }; + testConcatLines = { + expr = concatLines ["a" "b" "c"]; + expected = "a\nb\nc\n"; + }; + testSplitStringsSimple = { expr = strings.splitString "." "a.b.c.d"; expected = [ "a" "b" "c" "d" ]; |