Adds an element into a list if it doesn’t already exist (set-insertion).
add(xs:list, x:any) -> listDescription
Section titled “Description”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.
xs: list
Section titled “xs: list”The list to add to.
x: any
Section titled “x: any”An element to add to the list. If this is of a type incompatible with the list,
it will be considered as null.
Examples
Section titled “Examples”Add a new element to a list
Section titled “Add a new element to a list”from {xs: [1, 2, 3]}xs = xs.add(4){xs: [1, 2, 3, 4]}Try to add an existing element
Section titled “Try to add an existing element”from {xs: [1, 2, 3]}xs = xs.add(2){xs: [1, 2, 3]}Add to an empty list
Section titled “Add to an empty list”from {xs: []}xs = xs.add("hello"){xs: ["hello"]}