Reference · Strings

join

signature
join(list | null, str=) -> str

What it does

The items of a list as one string, with a separator between them; without a separator they are put side by side. Each item is written as str writes it, so numbers, booleans and null join as their text and need no converting first. null as the list joins as the empty string.

Examples

print(join(["a", "b", "c"], ", "))print(join(["a", "b"]))print(join([1, 2.5, true, null], "|"))
output
a, b, cab1|2.5|true|null

Edge cases

print(join([], ","), join(null, ","), join(["only"], ", "))print(join([[1, "x"], { a: 1 }], " "))print(join([dec("1.50"), 2], "+"))print(join(["x", "y"], "\n"))
output
  only[1, "x"] { a: 1 }1.50+2xy

Errors

A first argument that is not a list or null, or a separator that is not a string, is a runtime error, not an error value. Text is split first with split.

this one fails
print(join("abc", ","))
output
line 1: `join` expects a list as argument 1, got str

Chaining

In a pipeline the list comes first and the separator is the argument:

print("a b c" | split(" ") | map(upper) | join("-"))print(["b", "a"] | sort | join(", "))print([1, 2, 3] | map((n) => n * n) | join(" "))
output
A-B-Ca, b1 4 9

See also

split, str, map, repeat

Thread
7Useful? Like it, or add to its thread below.

Thread 0 posts

On join(): questions, tips, corrections, and code that uses it.

No posts yet. The first one opens the thread.

    Edit this page on GitHub · every example's output was made by running it (tools/refcheck.mjs) · questions on Discord or r/quillo