You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fold_while has been deprecated in favor of try_fold, and will eventually be removed ( #223 ). However, there is little documentation on how to actually do this in an idiomatic way.
For example, this playground comparison is the best I could do and it looks awful. The iterator finishing early isn't an error - it's a totally acceptable condition.
I'm sure there's a better way to do this, but it would be nice to document that in fold_while or, perhaps, in try_fold (I'll be happy to open a MR for that if someone can give me a good example.)
I actually just committed almost that exact change to our codebase. It works great, except that .unwrap_or_else(|x| x) is a little janky. But it's totally workable until something else comes along.
Activity
scottmcm commentedon Aug 18, 2020
It's true that a different
impl Trymakes this much nicer -- I added one to libcore that's used internally to make things like this more readable:https://github.com/rust-lang/rust/blob/515c9fa505e18a65d7f61bc3e9eb833b79a68618/library/core/src/iter/mod.rs#L373-L378
NoraCodes commentedon Aug 20, 2020
Oh yeah, that's much nicer! Would we be amenable to including such a construct in
itertoolssince it's such a common case?NoraCodes commentedon Aug 20, 2020
Actually, never mind, that's silly.
jswrenn commentedon Aug 20, 2020
@NoraCodes I'll hold off on removing
fold_whilefor the foreseeable future, at least until a more ergonomic alternative is available.NoraCodes commentedon Aug 20, 2020
Thank you 🙏
jswrenn commentedon Aug 21, 2020
This feels like an abuse of import renaming, but...
I think this makes for a good demonstration of how to translate from
fold_whiletotry_fold.NoraCodes commentedon Aug 21, 2020
I actually just committed almost that exact change to our codebase. It works great, except that
.unwrap_or_else(|x| x)is a little janky. But it's totally workable until something else comes along.jswrenn commentedon Aug 21, 2020
Agreed. There's this old PR introducing
Result::into_innerfor situations like this, but it was unfortunately rejected: rust-lang/rust#54219undeprecate and optimize `fold_while`
jswrenn commentedon Sep 5, 2020
fold_whilewill be un-deprecated (and slightly optimized!) our next release (0.10.0) with #476.NoraCodes commentedon Sep 5, 2020
Merge #475 #476 #479
scottmcm commentedon Feb 7, 2021
...and I now have rust-lang/rfcs#3058 open to start moving
ControlFlowtowards stabilization.scottmcm commentedon Jun 14, 2021
Stabilization is now approved, but it'll take until September 9th to reach stable, so there's still a few months before any more work can happen here.
Rollup merge of rust-lang#85608 - scottmcm:stabilize-control-flow-enu…
Rollup merge of rust-lang#85608 - scottmcm:stabilize-control-flow-enu…