11#include <promeki/config.h>
12#if PROMEKI_ENABLE_CORE
19PROMEKI_NAMESPACE_BEGIN
29template <
typename Container> Container sorted(Container c) {
30 std::sort(c.begin(), c.end());
42template <
typename Container,
typename Compare> Container sorted(Container c, Compare comp) {
43 std::sort(c.begin(), c.end(), comp);
55template <
typename Container,
typename Predicate> Container filtered(
const Container &c, Predicate pred) {
57 for (
auto it = c.begin(); it != c.end(); ++it) {
58 if (pred(*it)) result += *it;
71template <
typename Container,
typename Transform>
auto mapped(
const Container &c, Transform fn) {
72 using ResultType =
decltype(fn(*c.begin()));
73 List<ResultType> result;
74 result.reserve(c.size());
75 for (
auto it = c.begin(); it != c.end(); ++it) {
89template <
typename Container,
typename Predicate>
bool allOf(
const Container &c, Predicate pred) {
90 return std::all_of(c.begin(), c.end(), pred);
101template <
typename Container,
typename Predicate>
bool anyOf(
const Container &c, Predicate pred) {
102 return std::any_of(c.begin(), c.end(), pred);
113template <
typename Container,
typename Predicate>
bool noneOf(
const Container &c, Predicate pred) {
114 return std::none_of(c.begin(), c.end(), pred);
124template <
typename Container,
typename Callable>
void forEach(
const Container &c, Callable fn) {
125 std::for_each(c.begin(), c.end(), fn);
138template <
typename Container,
typename Init,
typename BinaryOp>
139Init accumulate(
const Container &c, Init init, BinaryOp op) {
140 return std::accumulate(c.begin(), c.end(), init, op);
149template <
typename Container>
auto minElement(
const Container &c) {
150 return std::min_element(c.begin(), c.end());
159template <
typename Container>
auto maxElement(
const Container &c) {
160 return std::max_element(c.begin(), c.end());
171template <
typename Container,
typename Value>
bool contains(
const Container &c,
const Value &val) {
172 return std::find(c.begin(), c.end(), val) != c.end();