4 ms·
>But how do you compose functions then. You can't write Not all functions have to return an error. You can come across something like func(x, y, func() {
by konart 9y ago
>But how do you compose functions then. You can't write
Not all functions have to return an error.
You can come across something like
func(x, y, func() {
...
})
Pretty often.
Anyway, I'm not quite sure how is that different from, say, Ruby's begin...rescue.
- masklinn 9y ago> Anyway, I'm not quite sure how is that different from, say, Ruby's begin...rescue. Ruby lets you write foo(bar(baz())), the rescue block will just coalesce errors in any of the three calls. And because Go has no generics and its errors are not reified (handled through MRV which is a special language construct) you can't build abstractions like flatmap/then/>>= which would let you compose these functions (or function calls), you have to handroll every instance.
- erik_seaberg 9y agoAs a special case, Go does allow foo(bar()) if foo takes two args. What it doesn't allow is foo(bar(), baz()) with errors.
- masklinn 9y ago> As a special case, Go does allow foo(bar()) if foo takes two args Good to know (though somewhat disgusting), but for error-returning functions I would assume the external ones would take a single argument aka in foo(bar(baz()) I'd expect func foo(arg W) (result X, err error) func bar(arg V) (result W, err error) func baz() (result V, err error)