#iterator #sequence #value #no-std

yanked iter_seq

Stateless, transformable, abstract sequences of values

5 releases

new 0.2.1 Apr 21, 2025
0.2.0 Apr 20, 2025
0.1.2 Feb 22, 2025
0.1.1 Feb 22, 2025
0.1.0 Feb 22, 2025

#791 in Data structures

Download history 316/week @ 2025-02-19 68/week @ 2025-02-26 2/week @ 2025-03-05 2/week @ 2025-04-09 220/week @ 2025-04-16

222 downloads per month

MIT/Apache

34KB
891 lines

iter_seq

Stateless, transformable, abstract sequence of values.

This crate provides a mechanism for working with abstract stateless sequences of arbitrary values. In contrast, standard iterators are stateful—that is, their state can be changed by calling next.

One significant limitation of the stateful model is its inability to encode compile-time invariants, which can lead to unnecessary overhead that the compiler often cannot reliably optimize away. This crate provides a "wrapper" around standard iterators that must be irreversibly converted into an iterator before its elements can be consumed.

Example

use iter_seq::{Sequence, seq};

fn main() {
    let odd_squares = seq::from_fn(|i| 2 * i as u32 + 1).map(|i| i * i);

    let arr: [u32; 128] = odd_squares.take_exact_s::<128>()
        .collect_array();

    for (i, x) in arr.iter().enumerate() {
        let j = 2 * i as u32 + 1;
        assert_eq!(j * j, x);
    }
}

Dependencies

~0.5–1MB
~27K SLoC