Could you give a before/after example?
if predicate() { Some(thing) } else { None }
After:
predicate().then(|| thing)
the second, that magic is not clear, i'll keep using the Before personally
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.
https://web.archive.org/web/20080218051638/http://www.nikhil...
edit: thanks all, should have known it was a lambda :D, in Swift we can omit this. My first thought seeing "||" was some type of OR logic since it's in the context of if/else
The argument of then() is a function which is evaluated only if the bool is true.
|ar,gs| expr
So `|| expr` is just a lambda function that takes no arguments and evaluates to `expr`.rust: |x| x+x
swift: {x in x+x}
rust: || 42
swift: { 42 }