Skip to content
CCPEDIAby Unity Nodes
Discussions/App Development/Is there an idiomatic way to import record fields into the scope of a choice?Forum ↗

Is there an idiomatic way to import record fields into the scope of a choice?

App Development2 posts366 views3 likesLast activity Nov 2021
SH
ShaulOP
Nov 2021

For example

data Foo = Foo
  with
    a : Int
    b : Int
  deriving (Eq, Show)

template Bar
  with
    p : Party
    f : Foo
  where
    signatory p 
    choice DoSomething : () 
      controller p 
      do 
        let (a,b) = (f.a, f.b)
        let c = a + b
        pure ()
    

In the choice body, is there an idiomatic way to import a and b instead of let (a,b) = (f.a, f.b)?

ST
Stephen
Nov 2021

Yes, you can write let Foo{..} = f, where Foo is the name of the record type. This is an extension to let Foo{a, b} = f syntax, which you may prefer in some situations to skip variables or be slightly more explicit.

This and some other record dismantling tips can be found in this tutorial.

edit: I genuinely didn’t notice that your record type was also called Foo

← Back to Discussions