Created
December 6, 2016 19:34
-
-
Save steveklabnik/da82b51f9dbedd5321924927af091131 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pub fn sum_loop(nums: &[i32]) -> i32 { | |
let mut s = 0; | |
for i in nums { | |
s = s + i; | |
} | |
s | |
} | |
pub fn sum_fold(nums: &[i32]) -> i32 { | |
nums.into_iter().fold(0, |acc, x| acc + x) | |
} | |
pub fn sum_pointfree(nums: &[i32]) -> i32 { | |
nums.into_iter().fold(0, std::ops::Add::add) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment