I wonder if a name like into instead of foreach would make it a bit clearer that it’s a consuming, evaluating method. I’d love to have something like this, even though I’m unsure about what a clear name would be.
An into could possibly also be more useful than just eager iteration of a closure. It could take anything with an IteratorReceiver trait as argument. Some examples:
# the general use-case
range(0, 100).into(|n| println!("n {}", n));
# populating a Vec
let mut v = vec![1, 2, 3];
range(20, 50).into(&mut v);
range(100, 200).into(&mut v);
Channels might also be sane receivers.
Unsure if this could be done without requiring the closure to be passed as &mut |n| ... implicitly.