> On Oct 20, 2016, at 2:52 AM, Benjamin Spratling via swift-evolution 
> <swift-evolution@swift.org> wrote:
> 
> struct Note {
>       /// half-steps from middle-C, nil means the note is a rest
>       var pitch:Int?
>       //more properties
>       init?(xmlNode: XMLNode) {
>               if let pitchString:String = xmlNode.attributes[“pitch”], let 
> pitchInt:Int = Int(pitchString) {
>                       pitch = pitchInt
>               }
>               //more code
>       }
> }
> 
> I could go write an extension on String to provide a computed integer 
> property, but I’m not just talking about one case, I’m talking about all 
> cases where we convert to types in this way.
> 
> If “$” meant “identifier of result of previous expression”, I could write:
> 
> init?(xmlNode: XMLNode) {
>       pitch = xmlNode.attributes[“pitch”]?Int($)
>       //more code
> }

Pretty cryptic. What's wrong with this?

        pitch = xmlNode.attributes["pitch"].map { Int($0) }
-- 
Brent Royal-Gordon
Architechies

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

Reply via email to