4 ms·
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 s
by echaozh 12y ago
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?
- BruceIV 12y agoCheck out the RFC linked from the article for some thoughts on that: https://github.com/glaebhoerl/rfcs/blob/trait-based-exception-handling/active/0000-trait-based-exception-handling.md https://github.com/glaebhoerl/rfcs/blob/trait-based-exceptio...
- masklinn 12y ago> 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 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).
- steveklabnik 12y ago> 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.
- ben0x539 12y agoMapping 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.map http://doc.rust-lang.org/core/result/enum.Result.html#method... http://doc.rust-lang.org/core/option/enum.Option.html#method.map http://doc.rust-lang.org/core/option/enum.Option.html#method...