Better HN
topnewbestaskshowjobs
Log inSign up

JSoto

50 karma · joined Jan 1, 2013 (13y ago) · 7 submissions

Submissions

comment 10y ago · link · parent

iOS engineer who worked on the Fabric app here :) I gave a talk about this topic at a Swift conference last year, if you wanna check that out! https://www.youtube.com/watch?v=Ent6LJDIB3I

comment 11y ago · link · parent

Oh yeah that's a good point! (and a really interesting optimization that can be applied to immutable values)

comment 11y ago · link · parent

I agree that it would be a little cleaner, because it would express the intention better (the fact that you're simply giving out the same error). However, the type would be wrong:

Yeah, this is correct. This would be wrong:

    func map<U>(f: T -> U) -> Result<U> {
        switch self {
        case let .Value(value):
            return Result<U>.Value(Box(f(value.unbox)))
        case let .Error(error):
            // self is Result<T>, but the return type must be Result<U>
            return self
        }
    }
As for efficiency: like you mention, enum are value types. For this reason, they're passed by copy! So even returning self would return a copy of self, not the same instance :)

comment 11y ago · link · parent

Yeah, this is correct. This would be wrong:

    func map<U>(f: T -> U) -> Result<U> {
        switch self {
        case let .Value(value):
            return Result<U>.Value(Box(f(value.unbox)))
        case let .Error(error):
            // self is Result<T>, but the return type must be Result<U>
            return self
        }
    }

comment 11y ago · link · parent

Thanks!

I think that would make for another interesting article. I purposely ignored those details to make sure I kept my article more practical and less academic :) I also didn't mention the unit function of Monads (is that equivalent to one of the laws that you refer to?)

6.

Functor and Monad in Swift(javiersoto.me ↗)

50 points · by JSoto · 11y ago · 18 comments

7.

MSActiveConfig: Remote configuration and A/B Testing framework for iOS(github.com ↗)

8 points · by JSoto · 13y ago · discuss