-
Notifications
You must be signed in to change notification settings - Fork 61
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
c645049
commit b10045b
Showing
6 changed files
with
241 additions
and
1 deletion.
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
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 |
---|---|---|
@@ -0,0 +1,127 @@ | ||
#include "../../../include/xtd/linq/enumerable.hpp" | ||
#include "../../../include/xtd/as.hpp" | ||
#include "../../../include/xtd/invalid_operation_exception.hpp" | ||
#include "../../../include/xtd/literals.hpp" | ||
|
||
using namespace xtd; | ||
using namespace xtd::collections::generic; | ||
using namespace xtd::linq; | ||
|
||
decimal enumerable::average(const ienumerable<decimal>& source) { | ||
auto average = .0l; | ||
auto count = 0; | ||
for (auto item : source) { | ||
average += item; | ||
++count; | ||
} | ||
if (count == 0) throw invalid_operation_exception {}; | ||
return average / count; | ||
} | ||
|
||
double enumerable::average(const ienumerable<double>& source) { | ||
auto average = .0; | ||
auto count = 0; | ||
for (auto item : source) { | ||
average += item; | ||
++count; | ||
} | ||
if (count == 0) throw invalid_operation_exception {}; | ||
return average / count; | ||
} | ||
|
||
float enumerable::average(const ienumerable<float>& source) { | ||
auto average = .0f; | ||
auto count = 0; | ||
for (auto item : source) { | ||
average += item; | ||
++count; | ||
} | ||
if (count == 0) throw invalid_operation_exception {}; | ||
return average / count; | ||
} | ||
|
||
double enumerable::average(const ienumerable<int32>& source) { | ||
auto average = .0; | ||
auto count = 0; | ||
for (auto item : source) { | ||
average += as<double>(item); | ||
++count; | ||
} | ||
if (count == 0) throw invalid_operation_exception {}; | ||
return average / count; | ||
} | ||
|
||
double enumerable::average(const ienumerable<int64>& source) { | ||
auto average = .0; | ||
auto count = 0; | ||
for (auto item : source) { | ||
average += as<double>(item); | ||
++count; | ||
} | ||
if (count == 0) throw invalid_operation_exception {}; | ||
return average / count; | ||
} | ||
|
||
optional<decimal> enumerable::average(const ienumerable<optional<decimal>>& source) noexcept { | ||
auto average = .0l; | ||
auto count = 0; | ||
for (auto item : source) { | ||
if (!item.has_value()) continue; | ||
average += item.value(); | ||
++count; | ||
} | ||
if (count == 0) return nullopt; | ||
return average / count; | ||
} | ||
|
||
optional<double> enumerable::average(const ienumerable<optional<double>>& source) noexcept { | ||
auto average = .0; | ||
auto count = 0; | ||
for (auto item : source) { | ||
if (!item.has_value()) continue; | ||
average += item.value(); | ||
++count; | ||
} | ||
if (count == 0) return nullopt; | ||
return average / count; | ||
} | ||
|
||
optional<float> enumerable::average(const ienumerable<optional<float>>& source) noexcept { | ||
auto average = .0f; | ||
auto count = 0; | ||
for (auto item : source) { | ||
if (!item.has_value()) continue; | ||
average += item.value(); | ||
++count; | ||
} | ||
if (count == 0) return nullopt; | ||
return average / count; | ||
} | ||
|
||
optional<double> enumerable::average(const ienumerable<optional<int32>>& source) noexcept { | ||
auto average = .0; | ||
auto count = 0; | ||
for (auto item : source) { | ||
if (!item.has_value()) continue; | ||
average += as<double>(item.value()); | ||
++count; | ||
} | ||
if (count == 0) return nullopt; | ||
return average / count; | ||
} | ||
|
||
optional<double> enumerable::average(const ienumerable<optional<int64>>& source) noexcept { | ||
auto average = .0; | ||
auto count = 0; | ||
for (auto item : source) { | ||
if (!item.has_value()) continue; | ||
average += as<double>(item.value()); | ||
++count; | ||
} | ||
if (count == 0) return nullopt; | ||
return average / count; | ||
} | ||
|
||
void enumerable::throw_invalid_operation_exception() { | ||
throw invalid_operation_exception {}; | ||
} |
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