[OT] Some neat ideas from the Kotlin language
Daniel N via Digitalmars-d
digitalmars-d at puremagic.com
Sat Feb 20 02:04:16 PST 2016
On Friday, 19 February 2016 at 21:30:37 UTC, Yuxuan Shui wrote:
>> I think the same applies to Swift. But I think you're supposed
>> to use it like this:
>>
>> if let a = var {
>> // a is no unwrapped
>> }
>
> But you would need to give the unwrapped value a new name.
>
Swift also has guard, which solves this issue.
func ex(a: Int?) {
// unwrap (possible to add additional check if desired)
guard let a = a where a > 0 else {
return // fail
}
a.ok // a is now a plain validated Int
}
More information about the Digitalmars-d
mailing list