Skip to main content

List

Library of functions for the list type.

Functions

Avg

Computes the average value of a list of numbers.

Syntax:
List.Avg(list: list ...)
Parameters
  • list: The list to compute the average on.

Build

Builds a new list.

Syntax:
List.Build(values: anything ...)
Parameters
  • values: Values to add to the list.
Example:
List.Build(1,2,3,4,5)  // A collection with 5 elements.

Contains

Tests if some value is contained in a list.

Syntax:
List.Contains(list: list, value: anything)
Parameters
  • list: The list.
  • value: The value to search for.
Example:
List.Contains(List.Build(1,2,3), 2) // true

Count

Counts the number of elements in a list.

Syntax:
List.Count(list: list)
Parameters
  • list: The list to count elements.
Example:
List.Count(
List.Build(1,2,3)
) // 3

Distinct

Removes duplicate elements of a list.

Syntax:
List.Distinct(list: list)
Parameters
  • list: The list to remove duplicate elements from.

Empty

Creates an empty list.

Syntax:
List.Empty(type: type)
Parameters
  • type: The type of the elements of the empty list.
Example:
List.Empty(type int) // Empty list of int

EquiJoin

Joins two lists with an equality condition.

Syntax:
List.EquiJoin(first: list, second: list, firstKey: function, secondKey: function)
Parameters
  • first: The first list to join.
  • second: The second list to join.
  • firstKey: The join condition function, which receives a row with elements from the first list and returns the key to perform the equality join condition on.
  • secondKey: The join condition function, which receives a row with elements from the second list and returns the key to perform the equality join condition on.
Example:

let
first = [ {v: 1}, {v: 2}, {v: 3} ],
second = [ {n: 1, name: "One"}, {n: 2, name: "Two"} ]
in
List.EquiJoin(first, second, a -> a.v, b -> b.n)
// Returns:
// [ { v: 1, n: 1, name: "One" }, { v: 2, n: 2, name: "Two" } ]

Exists

Tests whether a predicate holds for at least one element of a list.

Syntax:
List.Exists(list: list, predicate: function)
Parameters
  • list: The list.
  • predicate: The function predicate.
Example:
List.Exists(
List.Build(1,2,3),
v -> v >= 2
) // true

Explode

Moves elements of a nested list into elements of the parent list

Syntax:
List.Explode(list: list, nested: list)
Parameters
  • list: The list to explode elements to.
  • nested: The list to explode elements from.
Example:

let data = [
{
title: "Less than 2",
numbers: [{v: 0}, {v: 1}]
},
{
title: "More than 2",
numbers: [{v: 3}, {v: 4}]
}
]
in
List.Explode(data, r -> r.numbers)

// Returns:
// [
// {
// title: "Less than 2",
// numbers: [{v: 0}, {v: 1}],
// v: 0,
// },
// {
// title: "Less than 2",
// numbers: [{v: 0}, {v: 1}],
// v: 1,
// },
// {
// title: "More than 2",
// numbers: [{v: 3}, {v: 4}],
// v: 3
// },
// {
// title: "More than 2",
// numbers: [{v: 3}, {v: 4}],
// v: 4
// }
// ]

Filter

Selects all elements of a list that satisfy a predicate.

Syntax:
List.Filter(list: list, predicate: function)
Parameters
  • list: The list to filter.
  • predicate: The function predicate, which receives an element of a list and must return true/false whether the element is to be seleected or not.
Example:
List.Filter(
List.Build(1,2,3),
v -> v >= 2
) // List.Build(2, 3)

FindFirst

Returns the first element of a list that satisfies a predicate.

Syntax:
List.FindFirst(list: list, predicate: function)
Parameters
  • list: The list.
  • predicate: The function predicate to apply to the elements.
Example:
List.FindFirst(
List.Build(1,2,3),
v -> v >= 2
) // 2

FindLast

Returns the last element of a list that satisfies a predicate.

Syntax:
List.FindLast(list: list, predicate: function)
Parameters
  • list: The list.
  • predicate: The function predicate to apply to the elements.
Example:
List.FindLast(
List.Build(1,2,3),
v -> v <= 2
) // 2

First

Selects the first element of a list.

Syntax:
List.First(list: list)
Parameters
  • list: The list to select the first element from.
Example:
List.First(List.Build(2, 3, 1)) // 2

From

Builds a list from the items of a collection.

Syntax:
List.From(collection: collection)
Parameters
  • collection: The collection to build the list from.
Example:
List.From(Collection.Build(1, 2, 3)) // List.Build(1, 2, 3)

Get

Selects an element from a list by index.

Syntax:
List.Get(list: list, index: int)
Parameters
  • list: The list to select the element from.
  • index: The index (starting from zero) of the element to select.
Example:

List.Get(List.Build(1,2,3,4,5), 2) // 3
List.Get(List.Build(1,2,3,4,5), 100) // "index out of bounds"

note

Selecting an element out of bounds returns an "index out of bounds" error.

GroupBy

Partitions the input list according to a key function.

Syntax:
List.GroupBy(list: list, predicate: function)
Parameters
  • list: The list to partition.
  • predicate: The partition function, which receives an elements of the list and returns the key to partition it by.

Join

Joins two lists given a join condition.

Syntax:
List.Join(first: list, second: list, condition: function)
Parameters
  • first: The first list to join.
  • second: The second list to join.
  • condition: The join condition function, which receives a row with elements from both lists and returns true for the elements to join.
Example:

let
first = [ {v: 1}, {v: 2}, {v: 3} ],
second = [ {n: 1, name: "One"}, {n: 2, name: "Two"} ]
in
List.Join(first, second, r -> r.v == r.n)
// Returns:
// [ { v: 1, n: 1, name: "One" }, { v: 2, n: 2, name: "Two" } ]

Last

Selects the last element of a list.

Syntax:
List.Last(list: list)
Parameters
  • list: The list to select the last element from.
Example:
List.Last(List.Build(3, 1, 2)) // 2

Max

Finds the largest element in a list.

Syntax:
List.Max(list: list)
Parameters
  • list: The list to find the largest element from.
Example:
List.Max(List.Build(2, 3, 1)) // 3

Min

Finds the smallest element in a list.

Syntax:
List.Min(list: list)
Parameters
  • list: The list to find the smallest element from.
Example:
List.Min(List.Build(3, 1, 2)) // 1

MkString

Concatenates all elements of a list in a string using start, end, and separator strings.

Syntax:
List.MkString(list: list, start: optional string, sep: optional string, end: optional string)
Parameters
  • list: A list.
  • start: The starting string.
  • sep: The separator string.
  • end: The ending string.
Example:
List.MkString(
List.Build("a", "b", "c"),
start="(", sep=":", end=")") // "(a:b:c)"

OrderBy

Orders this list according to the key functions and orderings passed as parameters.

Syntax:
List.OrderBy(list: list, key: function ..., order: string ...)
Parameters
  • list: The list to order.
  • key: The key ordering function, which receives an element of the list and returns the key.
  • order: The order: "ASC" or "DESC".
Example:
List.OrderBy(movies, m -> m.country, "ASC", m -> m.budget, "DESC")

Sum

Sums up all elements of a list.

Syntax:
List.Sum(list: list)
Parameters
  • list: The list to sum elements from.
Example:
List.Sum(List.Build(3, 1, 2)) // 6

Take

Selects first N elements of a list.

Syntax:
List.Take(list: list, n: int)
Parameters
  • list: The list to select the first N elements from.
  • n: The number of elements to select from the list.
Example:
List.Take(List.Build(3, 1, 2), 3) // [3 , 1]

Transform

Builds a new list by applying a function to each element of a list.

Syntax:
List.Transform(list: list, function: function)
Parameters
  • list: The list to read.
  • function: The mapping function, which receives an element of the list and returns a new element for the new list.
Example:
List.Transform(
List.Build(1,2,3),
v -> v * 10
) // List.Build(10, 20, 30)

Union

Merge the input lists into one.

Syntax:
List.Union(list: list ...)
Parameters
  • list: The lists to union.

Zip

Turns two lists into one by combining their corresponding elements in pairs until the shortest list is exhausted.

Syntax:
List.Zip(list1: list, list2: list)
Parameters
  • list1: A list.
  • list2: A list.
Example:
List.Zip(
List.Build(1,2,3),
List.Build("a", "b", "c")
) // List.Build({1, "a"}, {2, "b"}, {3, "c"})