logoalt Hacker News

knutzuilast Tuesday at 7:48 PM1 replyview on HN

That's technically not true.

You can pass multiple return values of a function as parameters to another function if they fit the signature.

for example:

  func process[T any](value T, err error) {
    if err != nil {
      // handle error
    }
    // handle value
  }

this can be used in cases such as control loops, to centralize error handling for multiple separate functions, instead of writing out the error handling separately for each function.

  for {
    process(fetchFoo(ctx))
    process(fetchBar(ctx))
  }

Replies

preroklast Tuesday at 8:31 PM

Well, if fetchBar requires fetchFoo to complete successfully, you still somehow have to handle it.

That said, there are libraries out there that implement Result as generic type and it's fine working with them, as well.

I don't see what the hubbub is all about.