-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1dea704
commit 5ee750c
Showing
10 changed files
with
108 additions
and
84 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
pub trait Average<A = Self>: Sized { | ||
fn average<I: Iterator<Item = A>>(iter: I) -> Self; | ||
} | ||
|
||
macro_rules! average_for_types { | ||
( $( $x:ident ),* ) => {$( | ||
impl Average for $x { | ||
fn average<I: Iterator<Item = Self>>(iter: I) -> Self { | ||
let sums = iter | ||
.enumerate() | ||
.fold((0, Self::default()), |acc, v| (acc.0 + 1, acc.1 + v.1)); | ||
sums.1 / (sums.0 as $x) | ||
} | ||
} | ||
)*} | ||
} | ||
|
||
average_for_types!(u8, u16, u32, u64, u128, i8, i16, i32, i64, i128, usize, f32, f64); |
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,12 @@ | ||
//! Provide the implement of LINQ to Objects, based on `Iterator`. | ||
mod average; | ||
mod m_builtin; | ||
mod m_distinct; | ||
mod m_enumerable; | ||
mod m_method; | ||
mod m_order_by; | ||
mod m_select; | ||
mod m_builtin; | ||
mod m_method; | ||
mod m_distinct; | ||
mod m_union; | ||
|
||
pub use m_enumerable::*; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -96,4 +96,4 @@ macro_rules! linq { | |
} | ||
|
||
#[cfg(test)] | ||
mod tests; | ||
mod tests; |
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
#[cfg(test)] | ||
|
||
pub mod iter_expr; | ||
pub mod iter_methods; | ||
pub mod iter_methods; |
Oops, something went wrong.