[swift-evolution] ternary operator ?: suggestion

Craig Cruden ccruden at novafore.com
Sat Jan 9 23:00:54 CST 2016

map and dictionary syntax would not go together.  map (or any function that takes a block of code) takes a block of functional code that applies that function to all elements of a collection (potentially value/optional) .   The map idea was to extend this to allow pattern matching through { caseClauses } [also known as unary functions in another language].

{ caseClauses } expands to { caseClause [in :] ….. caseClause [in :] ….. etc. }

The multi-case ternary idea is a very very specialized case — and to me it looks like it would only allow things like a c/enum type switch returning values?

Whereas expanding map to allow caseClauses would allow for more functionality, things like returning functions based on pattern matching which would then be used later for other calculations etc. — as well as giving the simple functionality of a switch expression.

func interestCalculationA(balance: Double) -> Double {

    let mockValue = 1.00
    return mockValue

func interestCalculationB(balance: Double) -> Double {
    let mockValue = 2.00
    return mockValue

let interestCalc : Double -> Double = products.map {
    case .LiquidProduct:
    case .TermProduct:
    case .ThirdProduct:

let interest = interestCalc.map {x in x(100.00)}

> On 2016-01-10, at 8:58:42, Charles Constant via swift-evolution <swift-evolution at swift.org> wrote:
> 	let num = color.map {
> 		.Red: 100, 
> 		.Green:  200, 
> 		.Blue: 300,
> 		_ : -1 
> 	}
> Looks like I forgot to mention what my previous message regards: I mean that if we go with "map", I prefer the version that doesn't require "case" be written.
> I also realize whether we're verbose enough depends on how commonly people use this type of expression. If it is accepted, but unpopular, then I'd concede "verbose" makes more sense. 
> Anyways, I'll try to lurk for a while now, instead of posting, as I'm veering toward the bike-shed :)
>  _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160110/31b36ed4/attachment.html>

More information about the swift-evolution mailing list