Mapping through Parties

Hello DAML people,

I apologize for the straightforward question, yet, I’m not very good at Haskell nor Mapping functions.

Assume that I have the Template below;

template Agreement
    signatories: [Party]
    observers : [Party]
    observer observers
    signatory signatories
      unique signatories

I want to have only chosen parties as signatories or observers. Therefore I need some kind of mapping through them. It might be something similar to this:

ensure signatories `elem` mapOptional partyFromText ["Jean", "Pierre", "Paul"]

In order to iterate through each single party in “signatories” or “observers” lists in a way that these parties are assured to be one of the named parties who are specified explicitly there.

In the end, No signatory or observer that is not specified in the given list can be added to signatories or observers. Thank you.


By default you have an all function, which can be used like this:

ensure all (\p -> ...) signatories
-- fill in for ...

The problem you have with elem is that the left-hand argument in your example must be a Party, but your expression passes a [Party], right? Well, using all above, p has type Party, and ... is a Bool expression. Not coincidentally, elem returns a Bool itself, and if you check the docs for all, it precisely matches up with your “no [element] that is [not matching the given predicate function] can [occur in the list]” requirement.

Assuming you want to check both signatories and observers against the same list, you can append them together like (signatories <> observers) to check both lists at once. But maybe you mean to check against separate approved-party lists.


Thank you very much @Stephen. It works as its expected.

I feel compelled to note that, while Stephen’s answer does explain how to make this work, this is actually not something you should do in most Daml systems.

Hard-coding party identifiers is a really bad idea. If you want to restrict what parties can do, it’s much better to do that through contracts on the ledger.


Thank you for the alert @Gary. Yes, you’re definitely right. I already changed it.