Skip to main content

while_changing

Function while_changing 

Source
pub fn while_changing<T, F>(value: T, func: F) -> T
where T: Clone + PartialEq, F: Fn(T) -> T,
Expand description

Applies a transformation to a given expression until a fix point is reached.

§Arguments

  • value - The initial value to transform
  • func - The transformation function

§Returns

The transformed value when it stops changing

§Example

use polyglot_sql::helper::while_changing;

// Example: keep dividing by 2 until odd
let result = while_changing(16, |n| if n % 2 == 0 { n / 2 } else { n });
assert_eq!(result, 1);