Skip to content

List functions

Every function in this family, with its signature and examples. Each example runs as a test of the language. See Language basics for how calls, types, and operators work.

at

Returns the value at the specified index in a list.

at(list, index)

Also callable as receiver.at(…), with the receiver as the first argument.

  • at([1, 2, 3], 1) gives 2
  • [1, 2, 3].at(1) gives 2

first

Returns the first item in the list.

first(list)

Also callable as receiver.first(…), with the receiver as the first argument.

  • first([1, 2, 3]) gives 1
  • [1, 2, 3].first() gives 1

last

Returns the last item in the list.

last(list)

Also callable as receiver.last(…), with the receiver as the first argument.

  • last([1, 2, 3]) gives 3
  • [1, 2, 3].last() gives 3

slice

Returns the items of the list from the provided start index (inclusive) to the end index (exclusive).

slice(list, start, end)

Also callable as receiver.slice(…), with the receiver as the first argument.

  • slice([1, 2, 3], 1, 2) gives [2]
  • slice(["a", "b", "c"], 1) gives ["b", "c"]

concat

Returns the concatenation of multiple lists. The text form concat(text, …), which joins text, is a Fontana extension: Notion 2.0 joins text with + or join().

concat(list, …)
concat(text, …)

Also callable as receiver.concat(…), with the receiver as the first argument.

  • concat([1, 2], [3, 4]) gives [1, 2, 3, 4]
  • concat(["a", "b"], ["c", "d"]) gives ["a", "b", "c", "d"]
  • concat("dog", "go") gives "doggo"

sort

Returns the list in sorted order.

sort(list)

Also callable as receiver.sort(…), with the receiver as the first argument.

  • sort([3, 1, 2]) gives [1, 2, 3]
  • ["b", "c", "a"].sort() gives ["a", "b", "c"]

reverse

Returns the reversed list.

reverse(list)

Also callable as receiver.reverse(…), with the receiver as the first argument.

  • reverse(["green", "eggs", "ham"]) gives ["ham", "eggs", "green"]

join

Returns the values of the list with the joiner placed in between each of the values.

join(list, joiner)

Also callable as receiver.join(…), with the receiver as the first argument.

  • join(["a", "b", "c"], ", ") gives "a, b, c"
  • join(["dog", "go"], "") gives "doggo"

split

Returns the list of values created by separating a text input at a separator.

split(text, separator)

Also callable as receiver.split(…), with the receiver as the first argument.

  • split("apple,pear,orange", ",") gives ["apple", "pear", "orange"]

unique

Returns the list of unique values in the input list.

unique(list)

Also callable as receiver.unique(…), with the receiver as the first argument.

  • unique([1, 1, 2]) gives [1, 2]
  • ["a", "b", "a"].unique() gives ["a", "b"]

includes

Returns true if the list contains the specified value, and false otherwise.

includes(list, value)

Also callable as receiver.includes(…), with the receiver as the first argument.

  • includes(["a", "b", "c"], "b") gives true
  • includes([1, 2, 3], 4) gives false

find

Returns the first item in the list for which the condition evaluates to true.

find(list, condition)

Also callable as receiver.find(…), with the receiver as the first argument.

  • find(["a", "b", "c"], current == "b") gives "b"
  • [1, 2, 3].find(current > 1) gives 2

findIndex

Returns the index of the first item in the list for which the condition is true, or -1 when none is.

findIndex(list, condition)

Also callable as receiver.findIndex(…), with the receiver as the first argument.

  • findIndex(["a", "b", "c"], current == "b") gives 1
  • [1, 2, 3].findIndex(current > 5) gives -1

filter

Returns the values in the list for which the condition is true.

filter(list, condition)

Also callable as receiver.filter(…), with the receiver as the first argument.

  • filter([1, 2, 3], current > 1) gives [2, 3]
  • filter(["a", "b", "c"], current == "a") gives ["a"]

some

Returns true if any item in the list satisfies the given condition, and false otherwise.

some(list, condition)

Also callable as receiver.some(…), with the receiver as the first argument.

  • some([1, 2, 3], current == 2) gives true
  • some(["a", "b", "c"], current.length() > 2) gives false

every

Returns true if every item in the list satisfies the given condition, and false otherwise.

every(list, condition)

Also callable as receiver.every(…), with the receiver as the first argument.

  • every([1, 2, 3], current > 0) gives true
  • every(["a", "b", "c"], current == "b") gives false

map

Returns the list populated with the results of calling the expression on every item in the input list.

map(list, expression)

Also callable as receiver.map(…), with the receiver as the first argument.

  • map([1, 2, 3], current + 1) gives [2, 3, 4]
  • map([1, 2, 3], current + index) gives [1, 3, 5]
  • [1, 2, 3].map(current * 2) gives [2, 4, 6]

flat

Flattens a list of lists into a single list.

flat(list)

Also callable as receiver.flat(…), with the receiver as the first argument.

  • flat([1, 2, 3]) gives [1, 2, 3]
  • flat([[1, 2], [3, 4]]) gives [1, 2, 3, 4]

count

Returns the number of items in the list.

count(list)

Also callable as receiver.count(…), with the receiver as the first argument.

  • count([1, 2, 3]) gives 3
  • [].count() gives 0

splice

Returns the list with the given number of items removed at the start index and the given values inserted there.

splice(list, start, deleteCount, value, …)

Also callable as receiver.splice(…), with the receiver as the first argument.

  • splice([1, 2, 3], 1, 1, "X") gives [1, "X", 3]
  • [1, 2, 3].splice(0, 2) gives [3]