Java Optional implementation in Golang

On the moment of writing generics in Golang (v1.26) are not very flexible, however you can implement something which almost feels like true Java.

Implementation

If you continue to extend this interface to make it even more java-like, you’ll quickly bump into current language limitations, however even this is enough to make the code more elegant.

Usage example