Skip to content

add

Adds an element into a list if it doesn’t already exist (set-insertion).

add(xs:list, x:any) -> list

The add function returns the list xs with x added at the end, but only if x is not already present in the list. This performs a set-insertion operation, ensuring no duplicate values in the resulting list.

The list to add to.

An element to add to the list. If this is of a type incompatible with the list, it will be considered as null.

from {xs: [1, 2, 3]}
xs = xs.add(4)
{xs: [1, 2, 3, 4]}
from {xs: [1, 2, 3]}
xs = xs.add(2)
{xs: [1, 2, 3]}
from {xs: []}
xs = xs.add("hello")
{xs: ["hello"]}

append, prepend, remove distinct

Last updated: