Hi, Daml community!
I’m trying to write a helper function with a notation:
extractFirstCidFromQueryResults: (Template t) => Script([(ContractId t, t)]) -> ContractId t
Usually, in the script context, I do it like this:
firstCidFromQuery <- fst . head <$> query @Template party
Now I want to write a helper function to hide this part:
fst . head <$>
And I can’t figure out how to do this… How can I do <$> as a first action in the function… I tried >>=, but it looks like I’m missing a concept here. Help!
Thanks!
PS
And I tried to query inside a function:
queryAndTakeFirstCid: (Template temp) => Party -> temp -> Script(ContractId temp)
queryAndTakeFirstCid party temp = query @temp party >>= \case
-- ^Not in scope: type variable ‘temp’
x:xs -> return $ fst x
_ -> error "no cids"
queryAndTakeFirstCid party MyTemplate
I will highly appreciate it if you can give me a clue on how to construct a function like this.