Re:Why Go is elegant and makes my code elegant
by anonymoushn on Wednesday April 09, 2014 @06:20PM
(#7562884)
Sorry, I don't mean to talk about Sum/Max/Min. I mean to talk about Either<A,B>, which is the appropriate return type for almost every Go function. In the presence of this type, the
"40 lines of mostly error handling" can then be reduced most of the way back to 5 lines using some function or control-flow construct that maps over the left half (or whichever half is chosen to not hold the exception) only.
Here's this in a really ugly language I would never recommend to anyone: http://stackoverflow.com/questions/3496304/how-do-i-process-...
And in a reasonable language: http://stackoverflow.com/questions/13503965/mapping-over-eit...
Edit: See also wting's comment below https://news.ycombinator.com/item?id=7562702