Unverified Commit 6a5f6f1a authored by Robert Hensing's avatar Robert Hensing Committed by GitHub
Browse files

lib: init strings.join (#446278)

parents 43363313 b37ac6a9
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -331,6 +331,7 @@ let
        hasInfix
        hasPrefix
        hasSuffix
        join
        stringToCharacters
        stringAsChars
        escape
+30 −0
Original line number Diff line number Diff line
@@ -41,6 +41,36 @@ rec {
    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.

+10 −0
Original line number Diff line number Diff line
@@ -69,6 +69,7 @@ let
    id
    ifilter0
    isStorePath
    join
    lazyDerivation
    length
    lists
@@ -435,6 +436,15 @@ runTests {

  # STRINGS

  testJoin = {
    expr = join "," [
      "a"
      "b"
      "c"
    ];
    expected = "a,b,c";
  };

  testConcatMapStrings = {
    expr = concatMapStrings (x: x + ";") [
      "a"