I've been working on a simple matrix library, rowcol.
use rowcol::prelude::*;
let f = Vector::<u64, U2>::new([1, 0]);
let a = Matrix::<u64, U2, U2>::new([[1, 1], [1, 0]]);
let mut p = Matrix::<u64, U2, U2>::identity();
for n in 0..51 {
println!("fib({:2}) = {}", n, (p * f)[1]);
p *= a;
}
I screwed around a bit today and implemented an Iterator extension trait for special-casing the first or last items:
I frequently find myself wanting this pattern, and it's actually not that hard to implement in Rust. I don't know if this is novel or if an alternate implementation exists. If not I guess I should publish a crate.
That seems super nice! You should open a pull request with the itertools crate.
Personally, I don't like the name first_last as that makes me think it only returns the first and the last element. I would prefer something like track_place, although that isn't quite right either.