Repeat: Difference between revisions

Added Rust implementation of Repeat
No edit summary
(Added Rust implementation of Repeat)
Line 665:
 
repeat(->{ puts "Example" }, 4)</lang>
 
=={{header|Rust}}==
<lang rust>// Repeat the function f, n times.
fn repeat<F>(f: &F, n: u32)
where F: Fn() {
for _ in 0..n {
f();
}
}
 
fn static_fn() {
print!("Static ");
}
 
fn main() {
// Repeat a static function.
repeat(&static_fn, 4);
 
println!("");
 
// Repeat an anonymous closure.
repeat(&|| print!("Closure "), 5);
}</lang>
 
=={{header|Scala}}==
Anonymous user