you are viewing a single comment's thread
view the rest of the comments
[–] 2 points 6 months ago* (3 children)

This is quite interesting, since the article states absolutely nothing about Go language.
Since, it's the most common or even fairly standard technique in the language:

func Hello(name string) (string, error) {
    // If no name was given, return an error with a message.
    if name == "" {
        return "", errors.New("empty name")
    }
    // ...
}

Source: go.dev/doc/tutorial/handle-errors

  • source
  • hideshow 3 child comments
  • [–] 5 points 6 months ago

    Go's val, err := maybeDoThing() pattern isn't the same thing because it's not a discriminated union like Rust's Result or C++'s std::expected or the Typescript example in the article. Moreover, due to restrictions in Go's generics, it's impossible to implement what is imo the most attractive pattern enabled by the discriminated union Result types - monadic operations.

  • source
  • parent