[swift-evolution] Brainstorming: Optional sugar inferred map
Paul Ossenbruggen
possen at gmail.com
Thu Jan 28 00:11:14 CST 2016
Kind works like optional chaining. In that the result remains an optional.
+1 for this, in that I agree that too often, control flow must be used for optionals. IMO clean code has fewer control flow statements and is more linear if possible.
> On Jan 27, 2016, at 10:01 PM, Craig Cruden <ccruden at novafore.com> wrote:
>
> Something like that would be good.
>
>
>> On 2016-01-28, at 12:50:50, Paul Ossenbruggen <possen at gmail.com <mailto:possen at gmail.com>> wrote:
>>
>> Maybe something like this?
>>
>> let n : Int? = 5
>>
>> let r = n? + 5
>>
>>
>>> On Jan 27, 2016, at 9:46 PM, Thorsten Seitz <tseitz42 at icloud.com <mailto:tseitz42 at icloud.com>> wrote:
>>>
>>> Too much hidden magic IMO. This would mean loosing the benefits of optionals, i.e. making explicit where optional cases occur and that handling the missing case has to be considered.
>>>
>>> -Thorsten
>>>
>>> Am 28.01.2016 um 06:30 schrieb Craig Cruden via swift-evolution <swift-evolution at swift.org <mailto:swift-evolution at swift.org>>:
>>>
>>>> Yes
>>>>> On 2016-01-28, at 12:28:40, Paul Ossenbruggen <possen at gmail.com <mailto:possen at gmail.com>> wrote:
>>>>>
>>>>> Trying to see if I got this. So the type of r would be Int? at the end of this? And if n were nil then r would be nil? Otherwise it r is 10?
>>>>>
>>>>>
>>>>>
>>>>>> On Jan 27, 2016, at 9:19 PM, Craig Cruden via swift-evolution <swift-evolution at swift.org <mailto:swift-evolution at swift.org>> wrote:
>>>>>>
>>>>>> Swift currently encourages a lot of conditional code - especially when it comes to optionals. In most cases when you are computing etc. on an Optional you would expect that you would want an optional result and things to be able to use optionals.
>>>>>>
>>>>>> In another language I generally just `map` one optional to another - which may not be the most readable code to some not use to optionals.
>>>>>>
>>>>>> I was wondering if maybe an expression is not available that it would rewrite the syntax to map from one to another value.
>>>>>>
>>>>>> So things like:
>>>>>>
>>>>>> let n : Int? = 5
>>>>>>
>>>>>> let r = n + 5
>>>>>>
>>>>>> would actually compile as
>>>>>>
>>>>>> let r = n.map {$0 + 5}
>>>>>> _______________________________________________
>>>>>> swift-evolution mailing list
>>>>>> swift-evolution at swift.org <mailto:swift-evolution at swift.org>
>>>>>> https://lists.swift.org/mailman/listinfo/swift-evolution <https://lists.swift.org/mailman/listinfo/swift-evolution>
>>>>>
>>>>
>>>> _______________________________________________
>>>> swift-evolution mailing list
>>>> swift-evolution at swift.org <mailto:swift-evolution at swift.org>
>>>> https://lists.swift.org/mailman/listinfo/swift-evolution <https://lists.swift.org/mailman/listinfo/swift-evolution>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160127/0b9432f5/attachment.html>
More information about the swift-evolution
mailing list