[swift-evolution] [Pitch] Use "where" in combination with "??" to provide Ternary-like functionality

Charles Constant charles at charlesism.com
Mon May 23 00:32:45 CDT 2016


Correction. My example reused "val" This is what I should have typed:

*    let foo = *
*        "positive" where ( bar > 0 )  ?? *
*        "negative" where ( bar < 0 ) ?? *
*        "zero"*

Sorry for that. My mind seems to switch itself off whenever I submit to
this list :)

Also, since my previous posts to this list about ternary and switch
assignment, etc. I now feel that including the variable name in the bool
side is useful. It would be a quick way to do the following sort of thing:

*    let foo = *
*        "positive" where ( bar > 0 )  ?? *
*        "negative" where ( bar < 0 ) ?? *
*        "animal zero" where ( is_animal == true ) ?? *
*        "normal zero"*
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160522/d36b091f/attachment.html>


More information about the swift-evolution mailing list