Skip to content
Permalink
Browse files

add ability to sum Value with an Iterator

  • Loading branch information...
vincenthz committed Mar 14, 2019
1 parent 3167c64 commit df347531742bdf8bd8b0712c53e3a4619b4cf18a
Showing with 8 additions and 0 deletions.
  1. +8 −0 chain-impl-mockchain/src/value.rs
@@ -1,5 +1,6 @@
use chain_core::property;
use std::ops;
use std::slice::Iter;

/// Unspent transaction value.
#[cfg_attr(feature = "generic-serialization", derive(serde_derive::Serialize))]
@@ -10,6 +11,13 @@ impl Value {
pub fn zero() -> Self {
Value(0)
}

pub fn sum<I>(values: I) -> Result<Self, ValueError>
where
I: Iterator<Item = Self>,
{
values.fold(Ok(Value::zero()), |acc, v| acc? + v)
}
}

#[derive(Debug, Copy, Clone, PartialEq, Eq)]

0 comments on commit df34753

Please sign in to comment.
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.