pub fn find_run<T, E, C: Fn(&T, &T) -> Result<bool, E>>(
    list: &[T],
    is_greater: C,
) -> Result<(bool, usize), E> {
    let (first, second) = match list {
        [a, b, ..] => (a, b),
        _ => return Ok((false, list.len())),
    };
    let mut pos = 1;
    let gt = if is_greater(first, second)? {
        for pair in list[1..].windows(2) {
            if !is_greater(&pair[0], &pair[1])? {
                break;
            }
            pos += 1;
        }
        true
    } else {
        for pair in list[1..].windows(2) {
            if is_greater(&pair[0], &pair[1])? {
                break;
            }
            pos += 1;
        }
        false
    };
    Ok((gt, pos + 1))
}
/// Find a run. Returns true if it needs reversed, and false otherwise.
Find a run. Returns true if it needs reversed, and false otherwise.
Find a run . Returns true if it needs reversed and false otherwise .
pub fn find_run<T, E, C: Fn(&T, &T) -> Result<bool, E>>(
    list: &[T],
    is_greater: C,
) -> Result<(bool, usize), E> {
    let (first, second) = match list {
        [a, b, ..] => (a, b),
        _ => return Ok((false, list.len())),
    };
    let mut pos = 1;
    let gt = if is_greater(first, second)? {
        for pair in list[1..].windows(2) {
            if !is_greater(&pair[0], &pair[1])? {
                break;
            }
            pos += 1;
        }
        true
    } else {
        for pair in list[1..].windows(2) {
            if is_greater(&pair[0], &pair[1])? {
                break;
            }
            pos += 1;
        }
        false
    };
    Ok((gt, pos + 1))
}
pub fn find_run < T , E , C : Fn ( & T , & T ) -> Result < bool , E > > ( list : & [ T ] , is_greater : C , ) -> Result < ( bool , usize ) , E > { let ( first , second ) = match list { [ a , b , .. ] => ( a , b ) , _ => return Ok ( ( false , list . len ( ) ) ) , } ; let mut pos = 1 ; let gt = if is_greater ( first , second ) ? { for pair in list [ 1 .. ] . windows ( 2 ) { if ! is_greater ( & pair [ 0 ] , & pair [ 1 ] ) ? { break ; } pos += 1 ; } true } else { for pair in list [ 1 .. ] . windows ( 2 ) { if is_greater ( & pair [ 0 ] , & pair [ 1 ] ) ? { break ; } pos += 1 ; } false } ; Ok ( ( gt , pos + 1 ) ) }
Find a run.
Find a run .
list
&[T]
is_greater
C
list
&[T]
is_greater
C