Good grief. I think you're right. Some how, a long time ago, I got it into my head that the order in which each part of the ternary got evaluated would cause problems for this kind of thing.
I've had a huge blindspot and I've been railing on the list for something I don't need for weeks. Wow, I couldn't be more embarassed. But I'm happy too, because I can go ahead and just use a chained ternary. Sorry all, and thanks. On Mon, May 23, 2016 at 6:26 PM, Dany St-Amant <[email protected]> wrote: > > Le 20 mai 2016 à 07:14, Charles Constant via swift-evolution < > [email protected]> a écrit : > > I wrote some code tonight to experiment with this kind of thing. I > apologize if it's off-topic for the thread, but it might be useful to > others who want to experiment. > > > > //: Playground - noun: a place where people can play > > import Cocoa > > infix operator • { precedence 180 } > infix operator → { associativity left precedence 70 } > infix operator … { associativity right precedence 60 } > > func → <T>( lhs: Bool, rhs: T ) -> T? { > return lhs ? rhs : nil > } > > func … <T>( lhs:T?, rhs:T ) -> T { > return lhs != nil ? lhs! : rhs > } > > func depends<I,O>( dep:I, _ closure: (I)->(O) ) -> O { > return closure( dep ) > } > > func • <I,O>( lhs: I, rhs: (I)->(O) ) -> O { > return depends( lhs, rhs ) > } > > /* Example using "depends" */ > > let > str:String, > i = 7 > > str = depends( i ){ > $0==2 → "two" … > $0==3 → "three" … > $0==4 → "four" … > "other" > } > > > Hmm… replacing -> by ?, and … by : you get: > > str = depends( i ){ > $0==2 ? "two" : > $0==3 ? "three" : > $0==4 ? "four" : > "other" > } > > which work as is without a need to define new operators. > > Dany > > /* Example using "•" operator as "depends" */ > > enum People { case Kurtz, Popescu, Lime, Martins } > enum Order { case First, Second, Third, Unknown } > > let > order:Order, > person:People = .Lime > > order = person • { > $0 == .Kurtz → .First … > $0 == .Popescu → .Second … > $0 == .Lime → .Third … > .Unknown > } > > > I also have some trepidation about posting it here, because it might have > bugs. I wans't sure what "precedence" and "associativity" should be, for > example. But it does make it more convenient to test alternative characters > for operators, etc. > > > > > > > > > > > > On Sat, Apr 9, 2016 at 12:05 AM, Vladimir.S via swift-evolution < > [email protected]> wrote: > >> >> On 09.04.2016 9:31, Brent Royal-Gordon wrote: >> >>> This design is still very much under development—it hasn't even been >>> reviewed, let alone added to the language. Here's the draft proposal:< >>> https://github.com/jtbandes/swift-evolution/blob/case-enumerable/proposals/0000-derived-collection-of-enum-cases.md >>> > >>> >>> I'm not saying that this will necessarily be a solution that ends up >>> being accepted—I'm merely saying that yes, it's something people are >>> thinking about and designing; it's just been inactive for a few weeks. >>> >> >> Oh, I see. Thank you for letting know. Just missed "you would be able" in >> your previous message, did read it as "you are able", so was trying to find >> this in current Swift version. OK, glad to know that most likely we'll have >> improvements in enums eterations for Swift 3.0. >> >> _______________________________________________ >> swift-evolution mailing list >> [email protected] >> https://lists.swift.org/mailman/listinfo/swift-evolution >> > > _______________________________________________ > swift-evolution mailing list > [email protected] > https://lists.swift.org/mailman/listinfo/swift-evolution > > >
_______________________________________________ swift-evolution mailing list [email protected] https://lists.swift.org/mailman/listinfo/swift-evolution
