Skip to content
CCPEDIAby Unity Nodes
App Development

Choice context / accessing `this` and `self`outside a template defn

2 posts192 views2 likesLast activity Jan 2022

  1. LucianoOP 1

    Say I have several templates which reuse code:

    template Factorable
      with
        party : Party
      where
        signatory Party
    
        choice CanBeFactored : *
          controller party
            do f this self
    
     f : Template t => t -> ContractId t -> *
    

    The code f can be factored out. But it depends on the context of the choice - i.e. I want to have access to self and this (and I’ve probably missed something else there).

    Do i always have to write a function taking these two arguments, or is there some typeclass or other clever mechanism for accessing the context of the choice?

  2. cocreature 1

    Writing a function is your only option here.