How do I extract the components of a tuple in DAML?

守給你的承諾、 提交于 2019-12-10 19:24:09

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!