sarugaku / resolvelib

Resolve abstract dependencies into concrete ones
ISC License
138 stars 31 forks source link

Lazy sequence iterview #107

Closed frostming closed 2 years ago

frostming commented 2 years ago

Result iterable returned by find_matches() won't be consumed all at once. Also unite the _FactoryIterableView with _SequenceIterableView With the change, the underlying iterable is guaranteed to be consumed only once.

uranusjr commented 2 years ago

I intentionally separated the two wrapper implementations to help debugging. _SequenceIterableView holds the original sequence, which can be random-accessed and iterated over multiple times, which is useful in the debugger to better identify the situation.

frostming commented 2 years ago

@uranusjr Fine, I revert the change to keep the SequenceIterableView, while FactoryIterableView is still optimized to avoid multiple calls to factory, especially when retrieving the first value is expensive.

frostming commented 2 years ago

@uranusjr Can you revisit this PR? I think it is worth merging since it will save a lot if it is expensive to construct the first candidate.