Skip to content

Instantly share code, notes, and snippets.

@berkes
Created October 4, 2022 09:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save berkes/5bebce03c9d6aa2da01e831af9f5fd95 to your computer and use it in GitHub Desktop.
Save berkes/5bebce03c9d6aa2da01e831af9f5fd95 to your computer and use it in GitHub Desktop.
ViewCount Example
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