mirror of
https://github.com/NixOS/nixpkgs.git
synced 2025-06-13 05:05:29 +03:00
lib/strings: add concatLines
Like `unlines` from Haskell. The aim is to replace the `concatStringsSep "\n"` pattern for generated files, which doesn't add a final newline.
This commit is contained in:
parent
f8fc2323e9
commit
ed0b8c26f1
3 changed files with 17 additions and 1 deletions
|
@ -93,7 +93,7 @@ let
|
||||||
subtractLists mutuallyExclusive groupBy groupBy';
|
subtractLists mutuallyExclusive groupBy groupBy';
|
||||||
inherit (self.strings) concatStrings concatMapStrings concatImapStrings
|
inherit (self.strings) concatStrings concatMapStrings concatImapStrings
|
||||||
intersperse concatStringsSep concatMapStringsSep
|
intersperse concatStringsSep concatMapStringsSep
|
||||||
concatImapStringsSep makeSearchPath makeSearchPathOutput
|
concatImapStringsSep concatLines makeSearchPath makeSearchPathOutput
|
||||||
makeLibraryPath makeBinPath optionalString
|
makeLibraryPath makeBinPath optionalString
|
||||||
hasInfix hasPrefix hasSuffix stringToCharacters stringAsChars escape
|
hasInfix hasPrefix hasSuffix stringToCharacters stringAsChars escape
|
||||||
escapeShellArg escapeShellArgs isValidPosixName toShellVar toShellVars
|
escapeShellArg escapeShellArgs isValidPosixName toShellVar toShellVars
|
||||||
|
|
|
@ -127,6 +127,17 @@ rec {
|
||||||
# List of input strings
|
# List of input strings
|
||||||
list: concatStringsSep sep (lib.imap1 f list);
|
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
|
/* Construct a Unix-style, colon-separated search path consisting of
|
||||||
the given `subDir` appended to each of the given paths.
|
the given `subDir` appended to each of the given paths.
|
||||||
|
|
||||||
|
|
|
@ -153,6 +153,11 @@ runTests {
|
||||||
expected = "a,b,c";
|
expected = "a,b,c";
|
||||||
};
|
};
|
||||||
|
|
||||||
|
testConcatLines = {
|
||||||
|
expr = concatLines ["a" "b" "c"];
|
||||||
|
expected = "a\nb\nc\n";
|
||||||
|
};
|
||||||
|
|
||||||
testSplitStringsSimple = {
|
testSplitStringsSimple = {
|
||||||
expr = strings.splitString "." "a.b.c.d";
|
expr = strings.splitString "." "a.b.c.d";
|
||||||
expected = [ "a" "b" "c" "d" ];
|
expected = [ "a" "b" "c" "d" ];
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue