With that quick introduction out of the way, we can now talk about the maybe type.
One of the things you may have already noticed is that almost all the operations return an error. Indeed, there are very few functions and methods that do not return an error. The logic behind this is simple: most of the errors are actually recoverable and have suitable recovery strategies.
However, for this project, we have one error recovery strategy: bubble up the error to the main function, where a log.Fatal will be called and the error will be inspected for debugging.
So, I defined maybe as follows:
type maybe struct { err error}func (m *maybe) do(fn func() (tensor.Tensor, error)) tensor.Tensor { if m.err != nil { return nil ...