logoalt Hacker News

galkklast Monday at 7:55 AM4 repliesview on HN

Idk, to me that constant

     Result<User, Error> 
looks extremely ugly and unergonomic, even just to type.

I understand that this is complicated topic and there were a lot of strong opinions even inside of Google about it, but god, I miss absl::StatusOr and ASSIGN_OR_RETURN. Yes, it won’t work without preprocessor magic (and that’s why this article goes through heavy functional stuff, otherwise it just cannot work in language like C#), but it’s so easy and natural to use in base case, it feels like cheating.


Replies

simonasklast Monday at 8:01 AM

I think in C# the way to solve this is to have two separate types, `Ok<TValue>` and `Err<TError>`, and provide implicit conversions for both to `Result<TValue, TError>`.

The static method approach showcased in the article is really long-winded.

show 1 reply
mooglylast Monday at 12:00 PM

Is this similar? https://github.com/amantinband/error-or

What's some of the "preprocessor magic" that makes this[1] more ergonomic to use?

[1]: https://github.com/abseil/abseil-cpp/blob/master/absl/status...

show 1 reply
pyralelast Monday at 9:13 AM

> I miss absl::StatusOr

Sounds like you would rather have an `ErrorOr<User>` than a `Result<User, Error>`.

Both are union types wrapped in a monadic construct.

show 1 reply