gpt4 book ai didi

f# - 类似于 F# 中的 yield break

转载 作者:行者123 更新时间:2023-12-04 23:10:26 24 4
gpt4 key购买 nike

如果先断后如何?

let WithdrawalCash (account, amount) = seq {        

if ( account.Balance.CurrentAmount - amount < 0.0m) then
yield NotEnoughMoneyForWithdrawal(account, amount)
// How to break here?

let newBalance = account.Balance.CurrentAmount - amount
yield CashWithdrawnEvent(account, newBalance)
}

最佳答案

不确定这会有所帮助,为什么不使用 else 子句?

let WithdrawalCash (account, amount) = seq {        

if ( account.Balance.CurrentAmount - amount < 0.0m) then
yield NotEnoughMoneyForWithdrawal(account, amount)
// How to break here?
else
let newBalance = account.Balance.CurrentAmount - amount
yield CashWithdrawnEvent(account, newBalance)
}
也看看:
Imperative computation in F# (II.) - Writing break and continue

关于f# - 类似于 F# 中的 yield break,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1992024/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com