<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">-1 on Bool extension, this should exist as a free function. Reason?<div class=""><br class=""></div><div class="">(1 + 1 == 2).ifTrue("foo", otherwise: "bar")</div><div class=""><br class=""></div><div class="">This: 1. doesn't look well; 2. is not clear and understandable; 3. doesn't allow condition to be a closure.</div><div class=""><br class=""><div class="">
<div style="color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><font color="#929292" class=""><br class="Apple-interchange-newline">Pozdrawiam – Regards,</font></div><div style="color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><font color="#929292" class="">Adrian Kashivskyy</font></div>
</div>
<br class=""><div><blockquote type="cite" class=""><div class="">Wiadomość napisana przez Sean Heber <<a href="mailto:sean@fifthace.com" class="">sean@fifthace.com</a>> w dniu 04.12.2015, o godz. 16:54:</div><br class="Apple-interchange-newline"><div class=""><div class="">Could alternatively could take a page from Smalltalk:<br class=""><br class=""> extension Bool {<br class=""> func ifTrue<T>(@autoclosure isTrue: () -> T, @autoclosure otherwise isFalse: () -> T) -> T {<br class=""> if self {<br class=""> return isTrue()<br class=""> } else {<br class=""> return isFalse()<br class=""> }<br class=""> }<br class=""> }<br class=""><br class="">:)<br class=""><br class="">l8r<br class="">Sean<br class=""><br class=""><br class=""><blockquote type="cite" class="">On Dec 4, 2015, at 1:40 AM, David Waite <<a href="mailto:david@alkaline-solutions.com" class="">david@alkaline-solutions.com</a>> wrote:<br class=""><br class="">Of course one could just drop it as a grammatical language feature and turn it a standard library feature of some form, e.g.:<br class=""><br class="">@warn_unused_result<br class="">func when<T>(@autoclosure expr: ()->Bool, @autoclosure value: ()->T, @autoclosure otherwise: ()->T) -> T {<br class=""> if expr() {<br class=""> return value()<br class=""> }<br class=""> else {<br class=""> return otherwise()<br class=""> }<br class="">}<br class=""><br class="">var a = when(1 + 1 == 2, value: "works", otherwise: "fails")<br class=""><br class="">print(a) // => “works"<br class=""><br class="">-DW<br class=""><br class=""><blockquote type="cite" class="">On Dec 4, 2015, at 12:26 AM, David Hart <<a href="mailto:david@hartbit.com" class="">david@hartbit.com</a>> wrote:<br class=""><br class="">I also tend to agree but I don't like the ordering in the Python version and would rather see the introduction of the then keyword<br class=""><br class="">On 04 Dec 2015, at 06:08, Sean Heber <<a href="mailto:sean@fifthace.com" class="">sean@fifthace.com</a>> wrote:<br class=""><br class=""><blockquote type="cite" class="">I agree that using ? for ternary feels.. uncomfortable in Swift. I wouldn't mind seeing Python-style or just eliminating it entirely in favor of simplicity.<br class=""><br class="">l8r<br class="">Sean<br class=""><br class="">On Dec 3, 2015, at 10:48 PM, Dan Appel <<a href="mailto:dan.appel00@gmail.com" class="">dan.appel00@gmail.com</a>> wrote:<br class=""><br class=""><blockquote type="cite" class="">I agree that ternary can make code unreadable, especially so with the ‘?’. I personally like the Haskel option the most, but it introduces a new keyword ‘then’, which isn’t great either. Python’s "y if x else z" is therefore, in my opinion, the best alternative.<br class=""><br class="">Also, I found it interesting how split the Rust community was about removing the ternary operator.<br class=""><br class="">— <br class="">Dan Appel<br class=""><br class="">On Thu, Dec 3, 2015 at 7:58 PM J. Cheyo Jimenez <<a href="mailto:cheyo@masters3d.com" class="">cheyo@masters3d.com</a>> wrote:<br class="">Would you consider replacing the C style ?: ternary operator to something that does not use the question mark and colon ? <br class=""><br class="">The use of "?" can be confusing when speed reading code with optionals. <br class=""><br class="">Consider this code as somebody learning swift as their first language.<br class="">let result = !condition ? 1 : 2<br class=""><br class=""><br class="">Some alternatives:<br class=""><br class="">Haskel <br class="">if predicate then expr1 else expr2<br class="">Python<br class="">result = x if a > b else y<br class="">The advantage of not using the question mark is that the language will be more consistency on the use of "?" to mean only optionals. <br class=""><br class=""><br class="">References:<br class=""><a href="https://devforums.apple.com/message/1020139#1020139" class="">https://devforums.apple.com/message/1020139#1020139</a><br class="">https://github.com/rust-lang/rust/issues/1698#issuecomment-3705066<br class=""> _______________________________________________<br class="">swift-evolution mailing list<br class="">swift-evolution@swift.org<br class="">https://lists.swift.org/mailman/listinfo/swift-evolution<br class=""><br class="">_______________________________________________<br class="">swift-evolution mailing list<br class="">swift-evolution@swift.org<br class="">https://lists.swift.org/mailman/listinfo/swift-evolution<br class=""></blockquote><br class="">_______________________________________________<br class="">swift-evolution mailing list<br class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class="">https://lists.swift.org/mailman/listinfo/swift-evolution<br class=""></blockquote> _______________________________________________<br class="">swift-evolution mailing list<br class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class="">https://lists.swift.org/mailman/listinfo/swift-evolution<br class=""></blockquote><br class=""></blockquote><br class="">_______________________________________________<br class="">swift-evolution mailing list<br class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class="">https://lists.swift.org/mailman/listinfo/swift-evolution<br class=""></div></div></blockquote></div><br class=""></div></body></html>