I am once again advocating for for-else in rust. It's a completely elegant solution for for-expressions and while-expressions; it's a simple extension of the loop-expression behavior and has conceptual parity with if (not a useful expression) vs if-else
-
-
let value = loop { if thing.success() { break thing.value() } } ... let result = for item in &vec { if item.success() { break Ok(item.value()) } } else { Err("No successful items") }
-
What if a for that has valued breaks simply returned an Option? Then you could unwrap_or_else
- 3 more replies
New conversation -
-
-
I like the spicy take though!
Thanks. Twitter will use this to make your timeline better. UndoUndo
-
-
-
The neat thing about this for-loop-as-an-expression model is that there's only one way that makes sense - the else case will be the value if no break was executed.
-
This is exactly why I think it's a *way* better fit for Rust than Python.
End of conversation
New conversation -
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.