Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Different types in FoldWhile #259

Closed
mpdn opened this issue Jan 19, 2018 · 5 comments
Closed

Different types in FoldWhile #259

mpdn opened this issue Jan 19, 2018 · 5 comments

Comments

@mpdn
Copy link

mpdn commented Jan 19, 2018

Currently, FoldWhile requires the same type in Continue and Done, but it doesn't seem obvious why it shouldn't be able to use two different types.

It might be possible to add in a backwards compatible way, for example by adding the second type as a type parameter defaulting to the first type parameter.

@bluss
Copy link
Member

bluss commented Jan 19, 2018

Marking as breaking-change so that it is not forgotten at a breaking change-point.

@bluss
Copy link
Member

bluss commented Jan 19, 2018

Note that std Iterator::try_fold will give you what you want, I think.

@mpdn
Copy link
Author

mpdn commented Jan 19, 2018

Yeah, that seems like it would do exactly what I want. It does feel a little dirty to use Err for things that aren't really errors, so something like FoldWhile would still be nice if it implemented Try when it eventually stabilizes. However, I'll just use try_fold with Err for now, so thanks!

@scottmcm
Copy link
Contributor

scottmcm commented Feb 6, 2018

It does feel a little dirty to [...]

I agree -- core uses an enum very much like FoldWhile internally to make things clearer: https://github.com/rust-lang/rust/blob/master/src/libcore/iter/mod.rs#L356-L404

@bluss
Copy link
Member

bluss commented Nov 24, 2018

.fold_while() has been deprecated in favour of .try_fold, and that's why this change is not implemented. It could otherwise easily be implemented. #223 #318

@bluss bluss closed this as completed Nov 24, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants