Re:Rust 1.50
by momothereal on Thursday February 11, 2021 @12:24PM
(#26104361)
IMO it depends if you're already in a chaining context. I wouldn't use it in a simple if-else branch, but it also removes the need to use if-else when you're already in a 10-function long chain.
Before:
if a.b().c().d().e().f() { Some(g().h().i()) } else { None }
Now:
a().b().c().d().e().f().then(|| g().h().i())
Even better if you have multiple boolean returns in the chain.
The naming can be confusing since "then" is usually used for async operations.
Re:Rust 1.50
by steveklabnik on Thursday February 11, 2021 @12:39PM
(#26104600)
That ship had already sailed in Rust https://doc.rust-lang.org/stable/std/?search=then
Option and Result already have a `and_then` in addition to the futures methods you mention, so it should just always be assumed that then/and_then have slightly different meanings depending on the context.
Re:Rust 1.50
by alfiedotwtf on Friday February 12, 2021 @02:28AM
(#26111423)
I used to like explicit if/then and using match, but chaining really does reduce code. It can sometimes take a while to golf it down, but damn is it satisfying when it’s all so compact. Followed by a `cargo fmt` and it feels way more elegant than branching
the second, that magic is not clear, i'll keep using the Before personally