1use std::iter;
4
5use crate::Field;
6
7pub fn powers<F: Field>(val: F) -> impl Iterator<Item = F> {
9 iter::successors(Some(F::ONE), move |&power| Some(power * val))
10}
11
12#[cfg(test)]
13mod tests {
14 use super::*;
15 use crate::{BinaryField, BinaryField128bGhash};
16
17 #[test]
18 fn test_powers_against_pow() {
19 let generator = BinaryField128bGhash::MULTIPLICATIVE_GENERATOR;
20 let power_values: Vec<_> = powers(generator).take(10).collect();
21
22 for i in 0..10 {
23 assert_eq!(power_values[i], generator.pow([i as u64]));
24 }
25 }
26}