Skip to content

k_smallest[_by]/tail: similarities and differences #904

@Philippe-Cholet

Description

@Philippe-Cholet

I find my new tail (#899) quite similar to k_smallest and its recent variants: we fuse the iterator, collect a limited number of items, than update the resulting slice with iter.for_each.

In tail, I consume the iterator (doing so can have wanted side effects) even when n = 0 while k_smallest and variants do not but merely drop it.
In tail, I have a special case for n = 1 while k_smallest and variants do not (it could use a possibly faster min[_by]).

I think we should update k_smallest and k_smallest_general accordingly.

Do you see other differences we should fix?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions