Skip to content

Commit

Permalink
Merge pull request #50 from A-Manning/ash/sum-trait
Browse files Browse the repository at this point in the history
impl core::iter::Sum for Scalar
  • Loading branch information
str4d authored Oct 20, 2020
2 parents 8fe77da + faf7abc commit 080eaa7
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/scalar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -774,6 +774,18 @@ impl PrimeField for Scalar {
}
}

impl<T> core::iter::Sum<T> for Scalar
where
T: core::borrow::Borrow<Scalar>,
{
fn sum<I>(iter: I) -> Self
where
I: Iterator<Item = T>,
{
iter.fold(Self::zero(), |acc, item| acc + item.borrow())
}
}

#[test]
fn test_inv() {
// Compute -(q^{-1} mod 2^64) mod 2^64 by exponentiating
Expand Down

0 comments on commit 080eaa7

Please sign in to comment.