Go: Error Handling in Functional Style

Published:
Translations:no translations yet

Turns out, with generics coming with Go 1.18 we can implement type-safe Either, Maybe, and many other useful containers.

This means we can even pretend that we don’t have if err != nil idiom and chain operations like functional programmers do.

Compare classic and functional example below:

To make it work we need a little library.

Honestly, it’s simply fun that it works. I don’t think it’s a good idea to actually use it in serious Go code. Serious Go code must be dead simple.