[swift-evolution] ternary operator ?: suggestion

Jo Albright me at jo2.co
Fri Jan 8 02:35:30 CST 2016


> On Jan 8, 2016, at 2:36 AM, Craig Cruden via swift-evolution <swift-evolution at swift.org> wrote:
> 
>>> let commission = trade.map {
>>> 	case .Buy(let quantity, let price) where Double(quantity) * price > 10000 in
>>>     		Double(quantity) * price * vipCommissionRate / 100
>>> 	case .Buy(let quantity, let price) in
>>>     		Double(quantity) * price * commissionRate / 100
>>> 	case .Sell(let quantity, let price) where Double(quantity) * price > 10000 in
>>>     		Double(quantity) * price * vipCommissionRate / 100
>>> 	case .Sell(let quantity, let price) in
>>>     		Double(quantity) * price * commissionRate / 100
>>> }

Is there any reason it couldn’t be “switchMap” instead of “map”? Would follow the design of “flatMap” naming. It would also help explain what is happening by mapping based on a switch statement.

let commission = trade.switchMap {

    case .Buy(let quantity, let price) where Double(quantity) * price > 10000 in
    		Double(quantity) * price * vipCommissionRate / 100
    case .Buy(let quantity, let price) in
    		Double(quantity) * price * commissionRate / 100
    case .Sell(let quantity, let price) where Double(quantity) * price > 10000 in
    		Double(quantity) * price * vipCommissionRate / 100
    case .Sell(let quantity, let price) in
    		Double(quantity) * price * commissionRate / 100

}


 Nerd . Designer . Developer
Jo Albright


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160108/76f856d3/attachment.html>


More information about the swift-evolution mailing list