intersperse: Fix quadratic performance
This commit is contained in:
parent
2d9885db9e
commit
c399f94bb3
@ -29,8 +29,7 @@ rec {
|
|||||||
intersperse = separator: list:
|
intersperse = separator: list:
|
||||||
if list == [] || length list == 1
|
if list == [] || length list == 1
|
||||||
then list
|
then list
|
||||||
else [(head list) separator]
|
else tail (lib.concatMap (x: [separator x]) list);
|
||||||
++ (intersperse separator (tail list));
|
|
||||||
|
|
||||||
|
|
||||||
# Concatenate a list of strings with a separator between each element, e.g.
|
# 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;
|
addContextFrom = a: b: substring 0 0 a + b;
|
||||||
|
|
||||||
|
|
||||||
# Cut a string with a separator and produces a list of strings which were
|
# Cut a string with a separator and produces a list of strings which
|
||||||
# separated by this separator. e.g.,
|
# were separated by this separator; e.g., `splitString "."
|
||||||
# `splitString "." "foo.bar.baz"' returns ["foo" "bar" "baz"].
|
# "foo.bar.baz"' returns ["foo" "bar" "baz"].
|
||||||
splitString = _sep: _s:
|
splitString = _sep: _s:
|
||||||
let
|
let
|
||||||
sep = addContextFrom _s _sep;
|
sep = addContextFrom _s _sep;
|
||||||
|
Loading…
Reference in New Issue
Block a user