Is there a way to turn an Optional Int type to an Int type in Daml?
if (winningParticipant == betPayload.participantToWin)
then do
let
-- the below creates the following: (["Giants", "Jets"], [0.25, 1.13])
(evtParticipants, evtParticipantOdds) = unzip eventPayload.eventRecord.predictions
-- Get the index of the winning participant to use it to index into the evtParticipantOdds list
winningParticipantIndex = elemIndex winningParticipant evtParticipants
-- Get the odds of the winning participant to determine payoutRate
payoutRate = (!!) evtParticipantOdds winningParticipantIndex
-- Get the payout amt
payoutAmt = betPayload.betSlip.wager * payoutRate
The error we are receiving is the following: " Couldn’t match expected type ‘Int’
with actual type ‘Optional Int’
• In the second argument of ‘(!!)’, namely
‘winningParticipantIndex’
In the expression: (!!) evtParticipantOdds winningParticipantIndex
In an equation for ‘payoutRate’:
payoutRate = (!!) evtParticipantOdds winningParticipantIndextypecheck ".
In the code, we are trying to get the odds number of the winning participant of a given bet, however, when we are trying to get this using the (!!) to index into evtParticipantOdds using the winingParticipantIndex, however that returns a type of Optional Int, rather than a Int. Any suggestions?