Given a pair in DAML, e.g. constructed by (1, "test"), how can I get the first and second components out?
Asked
Active
Viewed 263 times
3
Neil Mitchell
- 9,090
- 1
- 27
- 85
bame
- 960
- 5
- 7
-
Can you show us your code? What have you tried? What were you expecting the result to be? – Bob Dalgleish Dec 13 '18 at 14:04
2 Answers
2
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.
Neil Mitchell
- 9,090
- 1
- 27
- 85
1
For a tuple that has a number of elements, you could use
let (a,_,c,_) = someFunction
-- do something to a or c
Frankie
- 113
- 5