4 ms·
> Needing to constantly check if a specific return value is not nil just seems so sloppy but I have yet to come across a "better" way as it appears to just be a
by AdieuToLogic 2y ago
> Needing to constantly check if a specific return value is not nil just seems so sloppy but I have yet to come across a "better" way as it appears to just be a Golang convention. Is there a good post about better ways to handle errors in Go?
As others have identified, not in the Go language. In other languages which support disjoint unions with "right-biased" operations, such as Haskell's Either[0], Scala's version[1], amongst others, having to explicitly check for error conditions is not required when an Either (or equivalent) is used.
0 - https://hackage.haskell.org/package/base-4.20.0.1/docs/Data-Either.html https://hackage.haskell.org/package/base-4.20.0.1/docs/Data-...
1 - https://www.scala-lang.org/api/3.x/scala/util/Either.html https://www.scala-lang.org/api/3.x/scala/util/Either.html