News for hackers. Stuff that matters.
Re:Swift 1.2 and Xcode 6.3 beta by wyager on Monday February 09, 2015 @06:41PM (#9024546)
> Awesome, the ability to unwrap multiple optionals on one line should be bolded, underlined and all caps at the top of this article

This is why it's lame that Swift's optionals are a language feature and not an in-language implementation.

In Haskell, optionals are Monads, which means there is a function

    join :: m (m a) -> m a
"Maybe" (Haskell's standard library Optional) is a monad, so you can unwrap/collapse them using Join.

You can also daisy-chain them together using >>=, a la

    fail1 :: Maybe a
    fail2 :: a -> Maybe b
    result = fail1 >>= fail2
If either fail1 or fail2 fails, the entire "result" function fails (i.e. returns "Nothing").

There are no comments on this comment yet.