Pairs are datatypes in Marigold that hold two values. They are useful for recursive functions and folds, and are easier to use than two item lists.
Pairs are created by putting two comma seperated items in parentheses.
([item 1],[item 2])
Or, using the builtin function notation:
PAIR [item 1] [item 2]
(This should only be used in pipelines if at all)
@xy.@b.b x y
Notice that it returns a function that takes in a boolean and plugs the two items in the pair into the boolean. This is because true is a function that takes in two items and returns the first, and false takes in two items and returns the second. This means that you use booleans to index pairs.
FIRST takes in a pair and returns the first item. This is preferable to using
true to index a pair, since it’s both more readable, and pipeline compatible.
FIRST [pair]
@p.p true
Similarly, SECOND takes in a pair and returns the second item. This is preferable to using
false to index a pair, since it’s both more readable, and pipeline compatible.
SECOND [pair]
@p.p false