lib: init strings.join
This commit is contained in:
@@ -331,6 +331,7 @@ let
|
|||||||
hasInfix
|
hasInfix
|
||||||
hasPrefix
|
hasPrefix
|
||||||
hasSuffix
|
hasSuffix
|
||||||
|
join
|
||||||
stringToCharacters
|
stringToCharacters
|
||||||
stringAsChars
|
stringAsChars
|
||||||
escape
|
escape
|
||||||
|
|||||||
@@ -41,6 +41,36 @@ rec {
|
|||||||
unsafeDiscardStringContext
|
unsafeDiscardStringContext
|
||||||
;
|
;
|
||||||
|
|
||||||
|
/**
|
||||||
|
Concatenates a list of strings with a separator between each element.
|
||||||
|
|
||||||
|
# Inputs
|
||||||
|
|
||||||
|
`sep`
|
||||||
|
: Separator to add between elements
|
||||||
|
|
||||||
|
`list`
|
||||||
|
: List of strings that will be joined
|
||||||
|
|
||||||
|
# Type
|
||||||
|
|
||||||
|
```
|
||||||
|
join :: string -> [ string ] -> string
|
||||||
|
```
|
||||||
|
|
||||||
|
# Examples
|
||||||
|
:::{.example}
|
||||||
|
## `lib.strings.join` usage example
|
||||||
|
|
||||||
|
```nix
|
||||||
|
join ", " ["foo" "bar"]
|
||||||
|
=> "foo, bar"
|
||||||
|
```
|
||||||
|
|
||||||
|
:::
|
||||||
|
*/
|
||||||
|
join = builtins.concatStringsSep;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Concatenate a list of strings.
|
Concatenate a list of strings.
|
||||||
|
|
||||||
|
|||||||
@@ -69,6 +69,7 @@ let
|
|||||||
id
|
id
|
||||||
ifilter0
|
ifilter0
|
||||||
isStorePath
|
isStorePath
|
||||||
|
join
|
||||||
lazyDerivation
|
lazyDerivation
|
||||||
length
|
length
|
||||||
lists
|
lists
|
||||||
@@ -435,6 +436,15 @@ runTests {
|
|||||||
|
|
||||||
# STRINGS
|
# STRINGS
|
||||||
|
|
||||||
|
testJoin = {
|
||||||
|
expr = join "," [
|
||||||
|
"a"
|
||||||
|
"b"
|
||||||
|
"c"
|
||||||
|
];
|
||||||
|
expected = "a,b,c";
|
||||||
|
};
|
||||||
|
|
||||||
testConcatMapStrings = {
|
testConcatMapStrings = {
|
||||||
expr = concatMapStrings (x: x + ";") [
|
expr = concatMapStrings (x: x + ";") [
|
||||||
"a"
|
"a"
|
||||||
|
|||||||
Reference in New Issue
Block a user