pub fn find_letter_ranges_by<L: Letter<L>>(seq: &[L], pred: impl Fn(L) -> bool) -> Vec<LetterRange<L>> {
  let len = seq.len();

  let mut result = Vec::<LetterRange<L>>::new();
  let mut i = 0_usize;
  let mut begin = 0_usize;
  let mut found_maybe = Option::<L>::default();
  while i < len {
    let letter = seq[i];

    // Find beginning of a range
    if pred(letter) {
      begin = i;
      found_maybe = Some(letter);
    }

    match found_maybe {
      // If there's a current range we are working on (for which we found a `begin`), extend it
      Some(found) => {
        // Rewind forward until we find a mismatch
        while i < len && seq[i] == found {
          i += 1;
        }

        // We found the end of the current range, so now it's complete
        let end = i;

        // Remember the range
        result.push(LetterRange::<L> { begin, end, letter });

        found_maybe = None;
      }
      None => {
        if i < len {
          i += 1;
        }
      }
    }
  }
  result
}
// Finds contiguous ranges (segments) in the sequence, such that for every character inside every range,
// the predicate function returns true and every range contains only the same letter.
//
// The predicate is a function that takes a character and returns boolean.
//
// For example if predicate returns `true` for characters A and C, this function will find ranges `AAAA` and `CCCCC`,
// but not `ZZZ` or `ACCCAC`.
Finds contiguous ranges (segments) in the sequence, such that for every character inside every range,
the predicate function returns true and every range contains only the same letter.

The predicate is a function that takes a character and returns boolean.


Finds contiguous ranges ( segments ) in the sequence such that for every character inside every range the predicate function returns true and every range contains only the same letter . The predicate is a function that takes a character and returns boolean .
pub fn find_letter_ranges_by<L: Letter<L>>(seq: &[L], pred: impl Fn(L) -> bool) -> Vec<LetterRange<L>> {
  let len = seq.len();
  let mut result = Vec::<LetterRange<L>>::new();
  let mut i = 0_usize;
  let mut begin = 0_usize;
  let mut found_maybe = Option::<L>::default();
  while i < len {
    let letter = seq[i];
    // Find beginning of a range
    if pred(letter) {
      begin = i;
      found_maybe = Some(letter);
    }
    match found_maybe {
      // If there's a current range we are working on (for which we found a `begin`), extend it
      Some(found) => {
        // Rewind forward until we find a mismatch
        while i < len && seq[i] == found {
          i += 1;
        }
        // We found the end of the current range, so now it's complete
        let end = i;
        // Remember the range
        result.push(LetterRange::<L> { begin, end, letter });
        found_maybe = None;
      }
      None => {
        if i < len {
          i += 1;
        }
      }
    }
  }
  result
}
pub fn find_letter_ranges_by < L : Letter < L > > ( seq : & [ L ] , pred : impl Fn ( L ) -> bool ) -> Vec < LetterRange < L > > { let len = seq . len ( ) ; let mut result = Vec :: < LetterRange < L > > :: new ( ) ; let mut i = 0_usize ; let mut begin = 0_usize ; let mut found_maybe = Option :: < L > :: default ( ) ; while i < len { let letter = seq [ i ] ; // Find beginning of a range if pred ( letter ) { begin = i ; found_maybe = Some ( letter ) ; } match found_maybe { // If there's a current range we are working on (for which we found a `begin`), extend it Some ( found ) => { // Rewind forward until we find a mismatch while i < len && seq [ i ] == found { i += 1 ; } // We found the end of the current range, so now it's complete let end = i ; // Remember the range result . push ( LetterRange :: < L > { begin , end , letter } ) ; found_maybe = None ; } None => { if i < len { i += 1 ; } } } } result }
Finds contiguous ranges (segments) in the sequence, such that for every character inside every range,
the predicate function returns true and every range contains only the same letter.
Finds contiguous ranges ( segments ) in the sequence such that for every character inside every range the predicate function returns true and every range contains only the same letter .
seq
&[L]
pred
impl Fn(L) -> bool
seq
&[L]
pred
impl Fn(L) -> bool