Darklang.Stdlib.List
Functions for working with lists โ the primary collection type in Darklang.
โก 18 functions
๐ 1 value
Values
let empty = []
Returns an empty list
Functions
let singleton (value: 'a) : List<'a>
Returns a one-element list containing the given value.
let head (list: List<'a>) : Option.Option<'a>
Returns
Some the head (first value) of a list. Returns None if the list is empty.
let tail (list: List<'a>) : Option.Option<List<'a>>
If the list contains at least one value, returns
Some with a list of every value other than the first. Otherwise, returns None.
let append (as: List<'a>) (bs: List<'a>) : List<'a>
Returns a new list with all values in
as followed by all values in bs, preserving the order.
let push (list: List<'a>) (value: 'a) : List<'a>
Add element to front of list.
let last (list: List<'a>) : Option.Option<'a>
Returns the last value in the list, wrapped in an option (
None if the list is empty).
let reverse (list: List<'a>) : List<'a>
Returns a reversed copy of the list.
let findFirst (list: List<'a>) (fn: 'a -> Bool) : Option.Option<'a>
Returns
Some firstMatch where firstMatch is the first value of the list for which fn returns true. Returns None if no such value exists.
let member (list: List<'a>) (value: 'a) : Bool
Returns
true if value is in the list.
let repeat (times: Int64) (value: 'a) : Result.Result<List<'a>, String>
Returns a list containing value repeated times times.
let length (list: List<'a>) : Int64
Returns the number of values in the list.
let range (lowest: Int64) (highest: Int64) : List<Int64>
Returns a list of numbers where each element is 1 larger than the previous. You provide the lowest and highest numbers in the list.
let fold (list: List<'a>) (init: 'b) (fn: 'b -> 'a -> 'b) : 'b
Folds list into a single value, by repeatedly applying
fn to any two pairs.
let flatten (list: List<List<'a>>) : List<'a>
Returns a single list containing the values of every list directly in list (does not recursively flatten nested lists).
let map (list: List<'a>) (fn: 'a -> 'b) : List<'b>
Applies
fn to each element of list and returns the new list.
let sort (list: List<'a>) : List<'a>
Returns a copy of list with every value sorted in ascending order.
let unique (list: List<'a>) : List<'a>
Returns the list with only unique values. Order will not be maintained.
let isEmpty (list: List<'a>) : Bool
Returns true if the list has no values.
Related Types
type Option<'v> =
| Some of 'v
| None
type Result<'Ok, 'Err> =
| Ok of 'Ok
| Error of 'Err