List
Library of functions for the list type.
Functions
Avg
Computes the average value of a list of numbers.
List.Avg(list: list ...)
Parameters
list
: The list to compute the average on.
Build
Builds a new list.
List.Build(values: anything ...)
Parameters
values
: Values to add to the list.
List.Build(1,2,3,4,5) // A collection with 5 elements.
Contains
Tests if some value is contained in a list.
List.Contains(list: list, value: anything)
Parameters
list
: The list.
value
: The value to search for.
List.Contains(List.Build(1,2,3), 2) // true
Count
Counts the number of elements in a list.
List.Count(list: list)
Parameters
list
: The list to count elements.
List.Count(
List.Build(1,2,3)
) // 3
Distinct
Removes duplicate elements of a list.
List.Distinct(list: list)
Parameters
list
: The list to remove duplicate elements from.
Empty
Creates an empty list.
List.Empty(type: type)
Parameters
type
: The type of the elements of the empty list.
List.Empty(type int) // Empty list of int
EquiJoin
Joins two lists with an equality condition.
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.
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.
List.Exists(list: list, predicate: function)
Parameters
list
: The list.
predicate
: The function predicate.
List.Exists(
List.Build(1,2,3),
v -> v >= 2
) // true
Explode
Moves elements of a nested list into elements of the parent list
List.Explode(list: list, nested: list)
Parameters
list
: The list to explode elements to.
nested
: The list to explode elements from.
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.
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.
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.
List.FindFirst(list: list, predicate: function)
Parameters
list
: The list.
predicate
: The function predicate to apply to the elements.
List.FindFirst(
List.Build(1,2,3),
v -> v >= 2
) // 2
FindLast
Returns the last element of a list that satisfies a predicate.
List.FindLast(list: list, predicate: function)
Parameters
list
: The list.
predicate
: The function predicate to apply to the elements.
List.FindLast(
List.Build(1,2,3),
v -> v <= 2
) // 2
First
Selects the first element of a list.
List.First(list: list)
Parameters
list
: The list to select the first element from.
List.First(List.Build(2, 3, 1)) // 2
From
Builds a list from the items of a collection.
List.From(collection: collection)
Parameters
collection
: The collection to build the list from.
List.From(Collection.Build(1, 2, 3)) // List.Build(1, 2, 3)
Get
Selects an element from a list by index.
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.
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"
Selecting an element out of bounds returns an "index out of bounds" error.
GroupBy
Partitions the input list according to a key function.
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.
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.
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.
List.Last(list: list)
Parameters
list
: The list to select the last element from.
List.Last(List.Build(3, 1, 2)) // 2
Max
Finds the largest element in a list.
List.Max(list: list)
Parameters
list
: The list to find the largest element from.
List.Max(List.Build(2, 3, 1)) // 3
Min
Finds the smallest element in a list.
List.Min(list: list)
Parameters
list
: The list to find the smallest element from.
List.Min(List.Build(3, 1, 2)) // 1
MkString
Concatenates all elements of a list in a string using start, end, and separator strings.
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.
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.
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".
List.OrderBy(movies, m -> m.country, "ASC", m -> m.budget, "DESC")
Sum
Sums up all elements of a list.
List.Sum(list: list)
Parameters
list
: The list to sum elements from.
List.Sum(List.Build(3, 1, 2)) // 6
Take
Selects first N elements of a list.
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.
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.
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.
List.Transform(
List.Build(1,2,3),
v -> v * 10
) // List.Build(10, 20, 30)
Union
Merge the input lists into one.
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.
List.Zip(list1: list, list2: list)
Parameters
list1
: A list.
list2
: A list.
List.Zip(
List.Build(1,2,3),
List.Build("a", "b", "c")
) // List.Build({1, "a"}, {2, "b"}, {3, "c"})