Skip to content

Commit

Permalink
lib.strings.intersperse -> lib.lists.intersperse.
Browse files Browse the repository at this point in the history
`intersperse` is defined within `lib.strings` yet does not work for
strings, only lists. Furthermore, it only returns a list. There is no
sense in a function that only works with lists being in the strings
library.
  • Loading branch information
pinktrink committed Dec 6, 2019
1 parent d7ca8fe commit 2dc54a6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
17 changes: 17 additions & 0 deletions lib/lists.nix
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,23 @@ rec {
reverseList = xs:
let l = length xs; in genList (n: elemAt xs (l - n - 1)) l;

/* Place an element between each element of a list
Type: intersperse :: a -> [a] -> [a]
Example:
intersperse "/" ["usr" "local" "bin"]
=> ["usr" "/" "local" "/" "bin"].
*/
intersperse =
# Separator to add between elements
separator:
# Input list
list:
if list == [] || length list == 1
then list
else tail (lib.concatMap (x: [separator x]) list);

/* Depth-First Search (DFS) for lists `list != []`.
`before a b == true` means that `b` depends on `a` (there's an
Expand Down
17 changes: 0 additions & 17 deletions lib/strings.nix
Original file line number Diff line number Diff line change
Expand Up @@ -41,23 +41,6 @@ rec {
*/
concatImapStrings = f: list: concatStrings (lib.imap1 f list);

/* Place an element between each element of a list
Type: intersperse :: a -> [a] -> [a]
Example:
intersperse "/" ["usr" "local" "bin"]
=> ["usr" "/" "local" "/" "bin"].
*/
intersperse =
# Separator to add between elements
separator:
# Input list
list:
if list == [] || length list == 1
then list
else tail (lib.concatMap (x: [separator x]) list);

/* Concatenate a list of strings with a separator between each element
Type: concatStringsSep :: string -> [string] -> string
Expand Down

0 comments on commit 2dc54a6

Please sign in to comment.