#Iterator - Sort by Key until error

7 messages · Page 1 of 1 (latest)

radiant elm
#

Hi! I have an Iterator which's items have the type Result<T: Ord, E>. I would like to create a sorted collection of this iterator, sorted by T as effectively as possible.

Would the item type just be T I would use Itertools::sorted_by_key. What I really need here is something that does just that but if it encounters a Result::Err variant it just returns that error.

#

Actually um I just looked at the implementation of sorted_by_key and it just collects into a Vec and sorts that 🤡, so I guess I might as well just do that directly...
But still, if anybody has better ideas, I'm open for them haha

bright surge
#

Iterators aren't really sortable, as a concept, so collecting is the best they can really do.

#

I don't think we have a function for sorting until an error in the comparison function

#

Be it in iterators or not

#

I'm not even sure how I'd implement one tbh

radiant elm
#

Yeah I figured there wouldn't really be a way to sort it without allocating some sort of collection, but i was hoping there'd be a more efficient way than just loading it all into a Vec