summary refs log tree commit diff
path: root/lib/strings.nix
diff options
context:
space:
mode:
authorEelco Dolstra <eelco.dolstra@logicblox.com>2015-07-24 15:55:39 +0200
committerEelco Dolstra <eelco.dolstra@logicblox.com>2015-07-24 15:58:34 +0200
commitc399f94bb3bfad7fab7760d4842b38c9642541b5 (patch)
treecc515fc6969951f1972f84fd0146230b7623c2d7 /lib/strings.nix
parent2d9885db9e8b790ba2f8fc69b50a073260822a4f (diff)
downloadnixpkgs-c399f94bb3bfad7fab7760d4842b38c9642541b5.tar
nixpkgs-c399f94bb3bfad7fab7760d4842b38c9642541b5.tar.gz
nixpkgs-c399f94bb3bfad7fab7760d4842b38c9642541b5.tar.bz2
nixpkgs-c399f94bb3bfad7fab7760d4842b38c9642541b5.tar.lz
nixpkgs-c399f94bb3bfad7fab7760d4842b38c9642541b5.tar.xz
nixpkgs-c399f94bb3bfad7fab7760d4842b38c9642541b5.tar.zst
nixpkgs-c399f94bb3bfad7fab7760d4842b38c9642541b5.zip
intersperse: Fix quadratic performance
Diffstat (limited to 'lib/strings.nix')
-rw-r--r--lib/strings.nix9
1 files changed, 4 insertions, 5 deletions
diff --git a/lib/strings.nix b/lib/strings.nix
index c5af703e4e1..bac03c9d7ad 100644
--- a/lib/strings.nix
+++ b/lib/strings.nix
@@ -29,8 +29,7 @@ rec {
   intersperse = separator: list:
     if list == [] || length list == 1
     then list
-    else [(head list) separator]
-         ++ (intersperse separator (tail list));
+    else tail (lib.concatMap (x: [separator x]) list);
 
 
   # Concatenate a list of strings with a separator between each element, e.g.
@@ -128,9 +127,9 @@ rec {
   addContextFrom = a: b: substring 0 0 a + b;
 
 
-  # Cut a string with a separator and produces a list of strings which were
-  # separated by this separator. e.g.,
-  # `splitString "." "foo.bar.baz"' returns ["foo" "bar" "baz"].
+  # Cut a string with a separator and produces a list of strings which
+  # were separated by this separator; e.g., `splitString "."
+  # "foo.bar.baz"' returns ["foo" "bar" "baz"].
   splitString = _sep: _s:
     let
       sep = addContextFrom _s _sep;