fn main() {
let rule = |i: (_, _), divisor, text| {
if i.0 % divisor == 0 {
(i.0, i.1 + text)
} else {
i
}
};
(0..101)
.enumerate()
.map(|i| (i.0, String::new()))
.map(|i| rule(i, 2, "Ping"))
.map(|i| rule(i, 3, "Fizz"))
.map(|i| rule(i, 5, "Buzz"))
.map(|i| rule(i, 7, "Bazz"))
.map(|i| rule(i, 11, "Whirl"))
.map(|i| {
if i.1.is_empty() {
format!("{}", i.0)
} else {
i.1
}
})
.for_each(|i| println!("{}", i));
}
https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=05e99de1df603ee45c1d916d9a2d5c03
In line 2, note that I need to tell the compiler that i
is a tuple. Why is this the case?