summaryrefslogtreecommitdiff
path: root/lib/strings.nix
diff options
context:
space:
mode:
authorNaïm Favier <n@monade.li>2022-12-10 15:56:30 +0100
committerNaïm Favier <n@monade.li>2022-12-10 15:56:30 +0100
commited0b8c26f127525a9ee66f895bdc894cdaa5d685 (patch)
tree608169ac5743d8693a16f34cb8206a62f243f3db /lib/strings.nix
parentMerge pull request #205424 from r-ryantm/auto-update/python310Packages.aioshelly (diff)
downloadnixpkgs-ed0b8c26f127525a9ee66f895bdc894cdaa5d685.tar.gz
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.
Diffstat (limited to 'lib/strings.nix')
-rw-r--r--lib/strings.nix11
1 files changed, 11 insertions, 0 deletions
diff --git a/lib/strings.nix b/lib/strings.nix
index 9a4f29380d0d..32132e83b242 100644
--- a/lib/strings.nix
+++ b/lib/strings.nix
@@ -127,6 +127,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.