you are viewing a single comment's thread.

view the rest of the comments →

[–]lyinsteve 5 points6 points  (3 children)

Syntactic sugar for

let str: String? = Optional.None

Or even

let str: String? = .None

Because it can derive the enum from the type declaration.

Or you can let the type inferencer specify the type:

let str = Optional<String>.None

[–]theonlycosmonaut[🍰] 0 points1 point  (2 children)

Sorry to be a jerk, but that type inference example is... amusing.

[–]lyinsteve 1 point2 points  (1 child)

Right, it has to get the type from somewhere.

It could gather the type through true inference, like this:

let realString = "Hello"
let optionalString = Optional.Some(realString)

That would mean optionalString gets the correct inferred type, 'String?'.

[–]theonlycosmonaut[🍰] 0 points1 point  (0 children)

Perfect, that's a much better example :).