Skip to content

Examples for Iterator::rposition(F) do not differentiate it from ::position(F) #101095

@ulzu

Description

@ulzu

https://doc.rust-lang.org/std/iter/trait.Iterator.html#method.rposition
Description should provide a clear meaning for 'index' – index within the collection, or index as number of iteration?
Examples for rposition should demonstrate a clear difference from position.

Here's the example of rposition with an added comparison with the result of the situation with position.

let a = [1, 2, 3];

let mut iter_p = a.iter();
let mut iter_r = a.iter();

assert_eq!(iter_p.position(|&x| x == 2), iter_r.rposition(|&x| x == 2));

My proposition: use the same example as position(F)

let a = [1, 2, 3, 4];

let mut iter = a.iter();

assert_eq!(iter.rposition(|&x| x >= 2), Some(3));

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-docsArea: Documentation for any part of the project, including the compiler, standard library, and tools

    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