Created
October 4, 2022 09:55
-
-
Save berkes/5bebce03c9d6aa2da01e831af9f5fd95 to your computer and use it in GitHub Desktop.
ViewCount Example
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
mod domain { | |
pub struct ViewCount { | |
value: usize, | |
} | |
impl ViewCount { | |
pub fn new(value: usize) -> Self { | |
Self { value } | |
} | |
pub fn value(&self) -> usize { | |
self.value | |
} | |
} | |
} | |
use domain::*; | |
fn main() { | |
let viewcounts = vec![ViewCount::new(3), ViewCount::new(5), ViewCount::new(7)]; | |
let sum: usize = Iterator::sum(viewcounts.iter().map(|vc| vc.value())); | |
println!("total views: {}", sum); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment