问题
Given a pair in DAML, e.g. constructed by (1, "test"), how can I get the first and second components out?
回答1:
Given a DAML pair x of type (Int, Text), you can get the first component (1 in your example) using the selector x._1 or the fst function as fst x. You can get the second component ("test" in your example) with x._2 or snd x.
The x._1 selector works on all tuples (pairs, triples and beyond), while fst only works on pairs. The function fst3 (and snd3, thd3) are available in DA.Tuple to work on triples.
回答2:
For a tuple that has a number of elements, you could use
let (a,_,c,_) = someFunction
-- do something to a or c
来源:https://stackoverflow.com/questions/53763514/how-do-i-extract-the-components-of-a-tuple-in-daml