Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

So it's a specialized mapping operator for the Result functor. Why restrict it to Result only? What about using option to denote a failure condition without a specific reason? Or other kinds of interesting functors?


Check out the RFC linked from the article for some thoughts on that:

https://github.com/glaebhoerl/rfcs/blob/trait-based-exceptio...


> What about using option to denote a failure condition without a specific reason?

Result is set up and marked to mandate its use, the compiler will complain if you ignore the result of a function returning a Result, not so for an Option. So idiomatically denoting a failure condition without a specific reason is Result<T, ()> not Option<T>: http://doc.rust-lang.org/std/result/#result-and-option.

Option<T> is for what it's name denotes, a value which may or may not be present (e.g. an optional field in a struct).


> Result is set up and marked to mandate its use,

To elaborate on this slightly, it's not that Result is special cased by the compiler, there's a 'must_use' attribute which ensures that you get a warning if you ignore it, and the definition of Result has it.


Mapping is just the map method. This is about early return, so maybe you could construe it as a specialized whatsit in the Cont monad.

http://doc.rust-lang.org/core/result/enum.Result.html#method... http://doc.rust-lang.org/core/option/enum.Option.html#method...




Consider applying for YC's Fall 2026 batch! Applications are open till July 27.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: