Solved: 53 - Pipeline Ranges
This commit is contained in:
@@ -1,17 +1,23 @@
|
||||
#include "pipeline_ranges.hpp"
|
||||
|
||||
#include <map>
|
||||
#include <ranges>
|
||||
|
||||
namespace cpp26 {
|
||||
|
||||
auto top_values_by_category(const std::vector<Record>& records, int min_value)
|
||||
-> std::vector<Record> {
|
||||
(void)records; (void)min_value;
|
||||
return {};
|
||||
auto top_values_by_category(const std::vector<Record>& records, const int min_value) -> std::vector<Record> {
|
||||
return records
|
||||
| std::views::filter([min_value](const auto& record) { return record.value > min_value; })
|
||||
| std::ranges::to<std::vector<Record>>();
|
||||
}
|
||||
|
||||
auto total_by_category(const std::vector<Record>& records)
|
||||
-> std::vector<std::pair<std::string, int>> {
|
||||
(void)records;
|
||||
return {};
|
||||
auto total_by_category(const std::vector<Record>& records) -> std::vector<std::pair<std::string, int>> {
|
||||
std::map<std::string, int> grouped;
|
||||
for (const auto&[category, value] : records) {
|
||||
grouped[category] += value;
|
||||
}
|
||||
return grouped
|
||||
| std::ranges::to<std::vector<std::pair<std::string, int>>>();
|
||||
}
|
||||
|
||||
} // namespace cpp26
|
||||
|
||||
Reference in New Issue
Block a user