[1:[2:[3:[4:[5:"Hello"]]]]] let a:String? ! switch dict[1] { case .None : a = .None case .Some(let d) : switch d[2] { case .None : a = .None case .Some(let d) : switch d[3] { case .None : a = .None case .Some(let d) : switch d[4] { case .None : a = .None case .Some(let d) : switch d[5] { case .None : a = .None case .Some(let x) : a = x } } } } }
{ case .None : a = .None case .Some(let d) : switch d[2] { case .None : a = .None case .Some(let d) : switch d[3] { case .None : a = .None case .Some(let d) : switch d[4] { case .None : a = .None case .Some(let d) : switch d[5] { case .None : a = .None case .Some(let x) : a = x } } } } }
• Code without nil is saner code. • Optionals are simple values, but do add complexity. • Monadic bind is a natural way to tame the complexity. • Swift deals with Optionals monadically, so do you.