by kortex · 5y ago · 0 comments
val, err := int_or_err(foo)
if err != nil { return nil, err}
return val.add(bar), nil
Vs result := int_or_err(foo)
return val.map(add,bar)
I'd even take some sort of result := int_or_err(foo)
return val.map(add,bar).tuple()
to return a val,err pair in order to match conventional go.Consistency is more important than conciseness. Clear is better than clever. Plus, a function invocation / .map() is heavier than an err != nil check / condition.
Don't get me wrong, I appreciate the Either pattern as an alternative to if err != nil, but I also appreciate the really dumb and straightforward approach of non-clever Go.