3

Given a pair in DAML, e.g. constructed by (1, "test"), how can I get the first and second components out?

Neil Mitchell
  • 9,090
  • 1
  • 27
  • 85
bame
  • 960
  • 5
  • 7

2 Answers2

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