-
Notifications
You must be signed in to change notification settings - Fork 560
Closed
Labels
Description
These functions have reasonable default implementations, but sometimes they can be improved.
- The default
Producer::fold_withjust converts to an iterator and passes that to theFolder.ChainProducer::fold_withdoes better by folding its two parts separately, which can reduce conditional branching. (This is much like the motivation for the customstd::iter::Chain::fold.)- Most of the other producers that wrap a base type could probably have a custom
fold_withtoo, if only to allow a chain base type to optimize itself as before.- e.g.
ClonedProducer::fold_withcould callself.base.fold_with(ClonedFolder { base: folder })
- e.g.
- The default
Folder::consume_iterjust picks off items one by one toconsume()them untilfull(). (If it weren't for that "full" short-circuiting, it could just callIterator::foldinstead.)SumFolder::consume_iterjust calls the standardIterator::sum(). (which actually is a fold()... here we know it will never be full.)- There may be other folders which can do a better job in
consume_itertoo.