kdungs / go-result

Result types for Go; because (T, error) can be considered a ✨ monad ✨.
MIT License
1 stars 0 forks source link

Consider removing the `Eager` versions from `baresult` #4

Closed kdungs closed 1 year ago

kdungs commented 1 year ago

The whole reason to introduce these helpers and treat (T, error) as a check monad is to improve ergonomics. With the eager versions, calling code has to always store intermediates because we're only allowed to wrap the result of a function call when it's the only argument. For example.

processed, err := baresult.Fmap(ProcessData)(os.ReadFile(filePath))

vs.

data, err := os.ReadFile(filePath)
processed, err := baresult.EagerFmap(ProcessData, data, err)

For the same reason, the eager versions also don't allow chaining. Come to think of it, we probably don't need the eager versions, at all. Best case scenario: #1 yields that the functions are inlined anyway 🤷 .

kdungs commented 1 year ago

Fixed by f6b1bad3b6c333c447fbbba167867b201599e23a