Record
Library of functions for the record type.
Functions
AddField
Adds a new field to a record.
Syntax:
Record.AddField(record: record, field=value)
Parameters
-
record
: The record to add the field to. -
field=value
: Field name mapping to value.
Returns
record
: The record with the new field.
Example:
let r = Record.Build(lat=46.518831258, lon=6.5593310)
in Record.AddField(r, name="EPFL")
// Result:
// { lat: 46.518831258, lon: 6.5593310, name: "EPFL" }
Build
Builds a record value.
Syntax:
Record.Build(field=value, ...)
Parameters
field=value, ...
: Pairs of field name mapping to value.
Returns
record
: The record value.
Example:
Record.Build(lat=46.518831258, lon=6.5593310)
// Result:
// {lat: 46.518831258, lon: 6.5593310}
Concat
Concatenates two records.
Syntax:
Record.Concat(record1: record, record2: record)
Parameters
-
record1
: First record to concatenate into one. -
record2
: Second record to concatenate into one.
Returns
record
: The concatenated record.
Example:
let r1 = Record.Build(x=1, y=2),
r2 = Record.Build(a="1", b="2")
in Record.Concat(r1, r2)
// Result:
// {x: 1, y: 2, a: "1", b: "2"}
Fields
Returns the field names of a record as a list of strings.
Syntax:
Record.Fields(record: record)
Parameters
record
: The record to obtain the fields from.
Returns
list(string)
: The list of field names.
Example:
let r = Record.Build(46.518831258, lon=6.5593310)
in Record.Fields(r)
// Result:
// List.Build("lat", "lon")
GetFieldByIndex
Gets a field from a record given an index.
Syntax:
Record.GetFieldByIndex(record: record, index: int)
Parameters
-
record
: The record to read the field from. -
index
: The index (aka position) of the field to get from the record.
Returns
- The value of the field at the given index.
Example:
let r = Record.Build(x=1, y=2, z=3)
in Record.GetFieldByIndex(r, 1)
// Result:
// 2
RemoveField
Removes a field from a record.
Syntax:
Record.RemoveField(record: record, field: string)
Parameters
-
record
: The record to remove the field from. -
field
: The name of the field to remove from the record.
Returns
record
: The record with the field removed.
Example:
let r = Record.Build(x=1, y=2, z=3)
in Record.RemoveField(r, "y")
// Result:
// { x: 1, z: 3 }