xtd 0.2.0
enumerable.hpp
Go to the documentation of this file.
1
4#pragma once
5#include "../collections/generic/helpers/allocator.hpp"
6//#include "../collections/generic/iequality_comparer.hpp"
7#include "../collections/generic/equality_comparer.hpp"
8#include "../collections/generic/enumerator.hpp"
9#define __XTD_CORE_INTERNAL__
10#include "../internal/__array_definition.hpp"
11#include "../internal/__key_value_pair_definition.hpp"
12#include "../internal/__list_definition.hpp"
13#undef __XTD_CORE_INTERNAL__
14#include "../decimal.hpp"
15#include "../iequatable.hpp"
16#include "../int32.hpp"
17#include "../int64.hpp"
18#include "../optional.hpp"
19#include "../size.hpp"
20#include "../static.hpp"
21#include <algorithm>
22#include <functional>
23
25template<class type_t>
26struct __opaque_xtd_linq_enumerable_collection__;
27template<class type_t, class param_t>
28struct __opaque_xtd_linq_lazy_enumerable__;
30
32namespace xtd {
34 namespace collections::generic {
35 template<class type_t>
36 class ienumerable;
37 }
39
41 namespace linq {
42
59 public:
61
64 template<class type_t>
66
68 template<class type_t>
70
72 template<class type_t>
74
76 template<class type_t>
78
80 template<class key_t, class value_t>
83
85
95 template<class source_t>
96 static source_t aggregate(const ienumerable<source_t>& source, const std::function<source_t(const source_t&, const source_t&)>& func) {
97 auto nb = 0;
98 auto aggregated = source_t {};
99 for (const auto& item : source)
100 if (nb++ == 0) aggregated = item;
101 else aggregated = func(aggregated, item);
102 return aggregated;
103 }
113 template<class source_t>
114 static source_t aggregate(const ienumerable<source_t>& source, const source_t& seed, const std::function<source_t(const source_t&, const source_t&)>& func) {
115 auto aggregated = seed;
116 for (const auto& item : source)
117 aggregated = func(aggregated, item);
118 return aggregated;
119 }
130 template<class accumulate_t, class source_t>
131 static accumulate_t aggregate(const ienumerable<source_t>& source, const accumulate_t& seed, const std::function<accumulate_t(const source_t&, const accumulate_t&)>& func) {
132 auto aggregated = seed;
133 for (const auto& item : source)
134 aggregated = func(aggregated, item);
135 return aggregated;
136 }
147 template<class source_t>
148 static source_t aggregate(const ienumerable<source_t>& source, const source_t& seed, const std::function<source_t(const source_t&, const source_t&)>& func, const std::function<source_t(const source_t&)>& result_selector) {
149 auto aggregated = seed;
150 for (const auto& item : source)
151 aggregated = func(aggregated, item);
152 return result_selector(aggregated);
153 }
166 template<class result_t, class accumulate_t, class source_t>
167 static result_t aggregate(const ienumerable<source_t>& source, const accumulate_t& seed, const std::function<accumulate_t(const source_t&, const accumulate_t&)>& func, const std::function<result_t(const accumulate_t&)>& result_selector) {
168 auto aggregated = seed;
169 for (const auto& item : source)
170 aggregated = func(aggregated, item);
171 return result_selector(aggregated);
172 }
173
182 template<class source_t>
183 static bool all(const ienumerable<source_t>& source, const std::function<bool(const source_t&)>& predicate) {
184 for (const auto& item : source)
185 if (!predicate(item)) return false;
186 return true;
187 }
188
197 template<class source_t>
198 static bool any(const ienumerable<source_t>& source) noexcept {
199 return source.begin() != source.end();
200 }
209 template<class source_t>
210 static bool any(const ienumerable<source_t>& source, const std::function<bool(const source_t&)>& predicate) {
211 for (const auto& item : source)
212 if (predicate(item)) return true;
213 return false;
214 }
215
224 template<class source_t>
225 static const ienumerable<source_t>& append(const ienumerable<source_t>& source, const source_t& element) noexcept {
226 static thread_local auto result = __opaque_xtd_linq_enumerable_collection__<source_t> {};
227 result = __opaque_xtd_linq_enumerable_collection__<source_t> {};
228 for (const auto& item : source)
229 result.items.push_back(item);
230 result.items.push_back(element);
231 return result;
232 }
233
234 /*
235 template<class source_t>
236 static const ienumerable<source_t>& append(const ienumerable<source_t>& source, const source_t& element) noexcept {
237 using param_type = std::tuple<source_t, enumerator<source_t>, source_t, bool>;
238 static thread_local auto result = __opaque_xtd_linq_lazy_enumerable__<source_t, param_type> {};
239
240 result = __opaque_xtd_linq_lazy_enumerable__<source_t, param_type> {
241 std::make_tuple(source_t {}, source.get_enumerator(), element, false),
242 [](param_type& params) {
243 auto& result = std::get<0>(params);
244 auto& source_enumerator = std::get<1>(params);
245 const auto& element = std::get<2>(params);
246 auto& appended = std::get<3>(params);
247
248 if (source_enumerator.move_next()) {
249 result = source_enumerator.current();
250 return true;
251 }
252
253 if (!appended) {
254 appended = true;
255 result = element;
256 return true;
257 }
258
259 return false;
260 },
261 [](param_type& params) {
262 auto& result = std::get<0>(params);
263 auto& source_enumerator = std::get<1>(params);
264 auto& appended = std::get<3>(params);
265
266 result = source_t {};
267 source_enumerator.reset();
268 appended = false;
269 }
270 };
271
272 return result;
273 }*/
274
282 template<class source_t>
283 static const ienumerable<source_t>& as_enumerable(const ienumerable<source_t>& source) noexcept {
284 return source;
285 }
293 template<class source_t>
294 static const ienumerable<source_t>& as_enumerable(std::initializer_list<source_t> source) noexcept {
295 static thread_local auto result = __opaque_xtd_linq_enumerable_collection__<source_t> {};
296 result = __opaque_xtd_linq_enumerable_collection__<source_t> {};
297 for (const auto& item : source)
298 result.items.push_back(item);
299 return result;
300 }
308 template<class collection_t>
309 static const auto& as_enumerable(const collection_t& source) noexcept {
310 using source_t = typename collection_t::value_type;
311 static thread_local auto result = __opaque_xtd_linq_enumerable_collection__<source_t> {};
312 result = __opaque_xtd_linq_enumerable_collection__<source_t> {};
313 for (const auto& item : source)
314 result.items.push_back(item);
315 return static_cast<const ienumerable<source_t>&>(result);
316 }
325 template<class input_iterator_t>
326 static const auto& as_enumerable(input_iterator_t first, input_iterator_t last) noexcept {
327 using source_t = typename std::decay<decltype(*first)>::type;
328 static thread_local auto result = __opaque_xtd_linq_enumerable_collection__<source_t> {};
329 result = __opaque_xtd_linq_enumerable_collection__<source_t> {};
330 for (auto iterator = first; iterator != last; ++iterator)
331 result.items.push_back(*iterator);
332 return static_cast<const ienumerable<source_t>&>(result);
333 }
342 template<class input_iterator_t>
343 static const auto& as_enumerable(input_iterator_t iterator, size_t length) noexcept {
344 return as_enumerable(iterator, iterator + length);
345 }
354 template<class source_t, size_t length>
355 static const auto& as_enumerable(const source_t (&array)[length]) noexcept {
356 return as_enumerable(array, array + length);
357 }
358
368 static double average(const ienumerable<double>& source);
373 static float average(const ienumerable<float>& source);
378 static double average(const ienumerable<xtd::int32>& source);
383 static double average(const ienumerable<xtd::int64>& source);
384
405
413 template<class result_t, class source_t>
414 static const ienumerable<result_t>& cast(const ienumerable<source_t>& source) noexcept;
415
422 template<class source_t>
424
430 template<class source_t>
431 static const ienumerable<source_t>& concat(const ienumerable<source_t>& first, const ienumerable<source_t>& second) noexcept {
432 static thread_local auto result = __opaque_xtd_linq_enumerable_collection__<source_t> {};
433 result = __opaque_xtd_linq_enumerable_collection__<source_t> {};
434 for (const auto& item : first)
435 result.items.push_back(item);
436 for (const auto& item : second)
437 result.items.push_back(item);
438 return static_cast<const ienumerable<source_t>&>(result);
439 }
440
446 template<class source_t>
447 static bool contains(const ienumerable<source_t>& source, const source_t& value) noexcept {
448 for (const auto& item : source)
449 if (item == value) return true;
450 return false;
451 }
452
459 template<class source_t>
460 static bool contains(const ienumerable<source_t>& source, const source_t& value, const xtd::collections::generic::iequality_comparer<source_t>& comparer) noexcept {
461 for (const auto& item : source)
462 if (comparer.equals(item, value)) return true;
463 return false;
464 }
465
473 template<class source_t>
474 static xtd::size count(const ienumerable<source_t>& source) noexcept {
475 auto count = xtd::size {0};
476 auto enumerator = source.get_enumerator();
477 while (enumerator.move_next()) ++count;
478 return count;
479 }
480
489 template<class source_t>
490 static xtd::size count(const ienumerable<source_t>& source, const std::function<bool(const source_t&)>& predicate) noexcept {
491 return where<source_t>(source,predicate).count();
492 }
493
499 template<class source_t>
500 static xtd::size count(const ienumerable<source_t>& source, const source_t& value) noexcept {
501 return count<source_t>(source, [value](const source_t& item) -> bool {return item == value;});
502 }
503
513 template<class key_t, class source_t>
514 static const ienumerable<key_value_pair<key_t, xtd::size>>& count_by(const ienumerable<source_t>& source, const std::function<key_t(const source_t&)>& key_selector) noexcept {
516 }
517
528 template<class key_t, class source_t>
529 static const ienumerable<key_value_pair<key_t, xtd::size>>& count_by(const ienumerable<source_t>& source, const std::function<key_t(const source_t&)>& key_selector, const iequality_comparer<key_t>& key_comparer) noexcept {
530 static thread_local auto result = __opaque_xtd_linq_enumerable_collection__<key_value_pair<key_t, xtd::size>> {};
531 result = __opaque_xtd_linq_enumerable_collection__<key_value_pair<key_t, xtd::size>> {};
532 auto keys = list<key_t> {};
533 auto enumerator = source.get_enumerator();
534 while (enumerator.move_next()) {
535 auto key = key_selector(enumerator.current());
536 auto index = size_t {0};
537 for (; index < keys.size(); ++index)
538 if (key_comparer.equals(keys[index], key)) break;
539 if (index < keys.size()) result.items[index] = {key, result.items[index].value() + 1};
540 else {
541 keys.push_back(key);
542 result.items.push_back({key, 1});
543 }
544 }
545 return static_cast<const ienumerable<key_value_pair<key_t, xtd::size>>&>(result);
546 }
547
555 template<class source_t>
556 static const ienumerable<source_t>& default_if_empty(const ienumerable<source_t>& source) noexcept {
557 return default_if_empty(source, source_t {});
558 }
559
568 template<class source_t>
569 static const ienumerable<source_t>& default_if_empty(const ienumerable<source_t>& source, const source_t& default_value) noexcept {
570 static thread_local auto result = __opaque_xtd_linq_enumerable_collection__<source_t> {};
571 result = __opaque_xtd_linq_enumerable_collection__<source_t> {};
572 if (!any(source)) result.items.push_back(default_value);
573 else for (const auto& item : source)
574 result.items.push_back(item);
575 return result;
576 }
577
584 template<class source_t>
585 static source_t first_or_default(const ienumerable<source_t>& source, const std::function<bool(const source_t&)>& predicate, const source_t& default_value) noexcept {
586 const auto& result = where(source, predicate);
587 return any(result) ? *result.begin() : default_value;
588 }
594 template<class source_t>
595 static source_t first_or_default(const ienumerable<source_t>& source, const std::function<bool(const source_t&)>& predicate) noexcept {
596 return first_or_default(source, predicate, source_t {});
597 }
603 template<class source_t>
604 static source_t first_or_default(const ienumerable<source_t>& source, const source_t& default_value) noexcept {
605 return any(source) ? *source.begin() : default_value;
606 }
611 template<class source_t>
612 static source_t first_or_default(const ienumerable<source_t>& source) noexcept {
613 return first_or_default(source, source_t {});
614 }
615
623 template<class type_t>
624 static const ienumerable<type_t>& range(type_t count) {
625 auto step = type_t {};
626 return range(type_t {}, count, ++step);
627 }
636 template<class type_t>
637 static const ienumerable<type_t>& range(type_t start, type_t count) {
638 auto step = type_t {};
639 return range(start, count, ++step);
640 }
647 template<class type_t>
648 static const ienumerable<type_t>& range(type_t start, type_t count, type_t step) {
649 using param_type = std::tuple<type_t, type_t, type_t, type_t>;
650 static thread_local auto result = __opaque_xtd_linq_lazy_enumerable__<type_t, param_type> {};
651
654
655 result = __opaque_xtd_linq_lazy_enumerable__<type_t, param_type> {
656 std::make_tuple(start, count, step, type_t {}),
657 [](param_type& params) {
658 auto& result = std::get<0>(params);
659 auto& count = std::get<1>(params);
660 auto& step = std::get<2>(params);
661 auto& index = std::get<3>(params);
662 if (index != 0) result += step;
663 return index++ < count;
664 },
665 [start, count, step](param_type& params) {
666 params = std::make_tuple(start, count, step, type_t {});
667 }
668 };
669 return result;
670 }
671
680 template<class source_t>
681 static const ienumerable<source_t>& from(const ienumerable<source_t>& source) noexcept {
682 return as_enumerable(source);
683 }
692 template<class source_t>
693 static const ienumerable<source_t>& from(std::initializer_list<source_t> source) noexcept {
694 return as_enumerable(source);
695 }
704 template<class collection_t>
705 static const auto& from(const collection_t& source) noexcept {
706 return as_enumerable(source);
707 }
719 template<class input_iterator_t>
720 static const auto& from(input_iterator_t first, input_iterator_t last) noexcept {
721 return as_enumerable(first, last);
722 }
732 template<class input_iterator_t>
733 static const auto& from(input_iterator_t iterator, size_t length) noexcept {
734 return as_enumerable(iterator, iterator + length);
735 }
745 template<class source_t, size_t length>
746 static const auto& from(const source_t (&array)[length]) noexcept {
747 return as_enumerable(array, array + length);
748 }
749
759 template<class result_t, class source_t>
760 static const ienumerable<result_t>& select(const ienumerable<source_t>& source, const std::function<result_t(const source_t&)>& selector) {
761 static thread_local auto result = __opaque_xtd_linq_enumerable_collection__<result_t> {};
762 result = __opaque_xtd_linq_enumerable_collection__<result_t> {};
763 for (const auto& item : source)
764 result.items.push_back(selector(item));
765 return result;
766 }
775 template<class source_t>
776 static const ienumerable<source_t>& select(const ienumerable<source_t>& source, const std::function<source_t(const source_t&)>& selector) {
777 static thread_local auto result = __opaque_xtd_linq_enumerable_collection__<source_t> {};
778 result = __opaque_xtd_linq_enumerable_collection__<source_t> {};
779 for (const auto& item : source)
780 result.items.push_back(selector(item));
781 return result;
782 }
792 template<class result_t, class source_t>
793 static const ienumerable<result_t>& select(const ienumerable<source_t>& source, const std::function<result_t(const source_t&, xtd::size)>& selector) {
794 static thread_local auto result = __opaque_xtd_linq_enumerable_collection__<result_t> {};
795 result = __opaque_xtd_linq_enumerable_collection__<result_t> {};
796 auto index = xtd::size {0};
797 for (const auto& item : source)
798 result.items.push_back(selector(item, index++));
799 return result;
800 }
809 template<class source_t>
810 static const ienumerable<source_t>& select(const ienumerable<source_t>& source, const std::function<source_t(const source_t&, xtd::size)>& selector) {
811 static thread_local auto result = __opaque_xtd_linq_enumerable_collection__<source_t> {};
812 result = __opaque_xtd_linq_enumerable_collection__<source_t> {};
813 auto index = xtd::size {0};
814 for (const auto& item : source)
815 result.items.push_back(selector(item, index++));
816 return result;
817 }
818
827 template<class source_t>
828 static const list<source_t>& to_list(const ienumerable<source_t>& source) noexcept;
829
838 template<class source_t>
839 static const ienumerable<source_t>& where(const ienumerable<source_t>& source, const std::function<bool(const source_t&)>& predicate) {
840 static thread_local auto result = __opaque_xtd_linq_enumerable_collection__<source_t> {};
841 result = __opaque_xtd_linq_enumerable_collection__<source_t> {};
842 for (const auto& item : source)
843 if (predicate(item)) result.items.push_back(item);
844 return result;
845 }
854 template<class source_t>
855 static const ienumerable<source_t>& where(const ienumerable<source_t>& source, const std::function<bool(const source_t&, xtd::size)>& predicate) {
856 static thread_local auto result = __opaque_xtd_linq_enumerable_collection__<source_t> {};
857 result = __opaque_xtd_linq_enumerable_collection__<source_t> {};
858 auto index = xtd::size {0};
859 for (const auto& item : source)
860 if (predicate(item, index++)) result.items.push_back(item);
861 return result;
862 }
864
865 private:
866 template<class source_t, class collection_t>
867 static const list<source_t>& collection_to_list(const collection_t& source) noexcept;
868 template<class source_t, class input_iterator_t>
869 static const list<source_t>& input_iterator_to_list(input_iterator_t first, input_iterator_t last) noexcept;
870 };
871 }
872}
873
874#include "../collections/generic/extensions/enumerable.hpp"
875#include "from.hpp"
Provides methods for creating, manipulating, searching, and sorting arrays, thereby serving as the ba...
Definition array.hpp:61
Provides a base class for implementations of the xtd::collections::generic::iequality_comparer <type_...
Definition equality_comparer.hpp:35
Exposes the enumerator, which supports a simple iteration over a collection of a specified type.
Definition ienumerable.hpp:36
Defines methods to support the comparison of objects for equality.
Definition iequality_comparer.hpp:34
Represents a strongly typed list of objects that can be accessed by index. Provides methods to search...
Definition list.hpp:80
static void throws(xtd::helpers::exception_case exception_case, const source_location &location=source_location::current())
Throws an exption with specified exception case.
Provides a set of static methods for querying objects that implement ienumerable <type_t>.
Definition enumerable.hpp:58
static const auto & from(const source_t(&array)[length]) noexcept
Returns the input typed as xtd::collections::generic::ienumerable <type_t>.
Definition enumerable.hpp:746
static const auto & as_enumerable(input_iterator_t first, input_iterator_t last) noexcept
Returns the input typed as xtd::collections::generic::ienumerable <type_t>.
Definition enumerable.hpp:326
static xtd::decimal average(const ienumerable< xtd::decimal > &source)
Computes the average of a sequence of xtd::decimal values.
static const ienumerable< xtd::array< source_t > > & chunk(const ienumerable< source_t > &source, xtd::size size)
Splits the elements of a sequence into chunks of size at most size.
static const ienumerable< source_t > & from(std::initializer_list< source_t > source) noexcept
Returns the input typed as xtd::collections::generic::ienumerable <type_t>.
Definition enumerable.hpp:693
static const auto & from(input_iterator_t first, input_iterator_t last) noexcept
Returns the input typed as xtd::collections::generic::ienumerable <type_t>.
Definition enumerable.hpp:720
static const ienumerable< result_t > & select(const ienumerable< source_t > &source, const std::function< result_t(const source_t &)> &selector)
Projects each element of a sequence into a new form.
Definition enumerable.hpp:760
static const auto & as_enumerable(input_iterator_t iterator, size_t length) noexcept
Returns the input typed as xtd::collections::generic::ienumerable <type_t>.
Definition enumerable.hpp:343
static xtd::optional< float > average(const ienumerable< xtd::optional< float > > &source) noexcept
Computes the average of a sequence of optional float values.
static const ienumerable< result_t > & cast(const ienumerable< source_t > &source) noexcept
Casts the elements of an xtd::collections::generic::ienumerable to the specified type.
static bool all(const ienumerable< source_t > &source, const std::function< bool(const source_t &)> &predicate)
Determines whether all elements of a sequence satisfy a condition.
Definition enumerable.hpp:183
typename xtd::collections::generic::ienumerable< type_t > ienumerable
Represents the ienumerable value type.
Definition enumerable.hpp:73
static xtd::optional< xtd::decimal > average(const ienumerable< xtd::optional< xtd::decimal > > &source) noexcept
Computes the average of a sequence of optional xtd::decimal values.
typename xtd::collections::generic::enumerator< type_t > enumerator
Represents the enumerator value type.
Definition enumerable.hpp:65
static const ienumerable< result_t > & select(const ienumerable< source_t > &source, const std::function< result_t(const source_t &, xtd::size)> &selector)
Projects each element of a sequence into a new form by incorporating the element's index.
Definition enumerable.hpp:793
static const ienumerable< source_t > & where(const ienumerable< source_t > &source, const std::function< bool(const source_t &)> &predicate)
Filters a sequence of values based on a predicate.
Definition enumerable.hpp:839
static double average(const ienumerable< xtd::int32 > &source)
Computes the average of a sequence of xtd::int32 values.
static bool any(const ienumerable< source_t > &source) noexcept
Determines whether a sequence contains any elements.
Definition enumerable.hpp:198
static bool any(const ienumerable< source_t > &source, const std::function< bool(const source_t &)> &predicate)
Determines whether any element of a sequence satisfies a condition.
Definition enumerable.hpp:210
static const ienumerable< type_t > & range(type_t start, type_t count)
Generates a sequence of integral numbers within a specified range.
Definition enumerable.hpp:637
static source_t aggregate(const ienumerable< source_t > &source, const source_t &seed, const std::function< source_t(const source_t &, const source_t &)> &func, const std::function< source_t(const source_t &)> &result_selector)
Applies an accumulator function over a sequence. The specified seed value is used as the initial accu...
Definition enumerable.hpp:148
static bool contains(const ienumerable< source_t > &source, const source_t &value, const xtd::collections::generic::iequality_comparer< source_t > &comparer) noexcept
Determines whether a sequence contains a specified element by using a specified equality comparer.
Definition enumerable.hpp:460
typename xtd::collections::generic::iequality_comparer< type_t > iequality_comparer
Represents the ienumerable value type.
Definition enumerable.hpp:69
typename xtd::collections::generic::list< type_t > list
Represents the list value type.
Definition enumerable.hpp:77
static xtd::optional< double > average(const ienumerable< xtd::optional< xtd::int32 > > &source) noexcept
Computes the average of a sequence of optional xtd::int32 values.
static const auto & from(input_iterator_t iterator, size_t length) noexcept
Returns the input typed as xtd::collections::generic::ienumerable <type_t>.
Definition enumerable.hpp:733
static const ienumerable< key_value_pair< key_t, xtd::size > > & count_by(const ienumerable< source_t > &source, const std::function< key_t(const source_t &)> &key_selector) noexcept
Returns the count of elements in the source sequence grouped by key.
Definition enumerable.hpp:514
static const ienumerable< source_t > & select(const ienumerable< source_t > &source, const std::function< source_t(const source_t &)> &selector)
Projects each element of a sequence into a new form.
Definition enumerable.hpp:776
static double average(const ienumerable< double > &source)
Computes the average of a sequence of double values.
static result_t aggregate(const ienumerable< source_t > &source, const accumulate_t &seed, const std::function< accumulate_t(const source_t &, const accumulate_t &)> &func, const std::function< result_t(const accumulate_t &)> &result_selector)
Applies an accumulator function over a sequence. The specified seed value is used as the initial accu...
Definition enumerable.hpp:167
static bool contains(const ienumerable< source_t > &source, const source_t &value) noexcept
Determines whether a sequence contains a specified element by using the default equality comparer.
Definition enumerable.hpp:447
static const ienumerable< source_t > & default_if_empty(const ienumerable< source_t > &source, const source_t &default_value) noexcept
Returns the elements of the specified sequence or the specified value in a singleton collection if th...
Definition enumerable.hpp:569
static double average(const ienumerable< xtd::int64 > &source)
Computes the average of a sequence of xtd::int64 values.
static const ienumerable< source_t > & as_enumerable(std::initializer_list< source_t > source) noexcept
Returns the input typed as xtd::collections::generic::ienumerable <type_t>.
Definition enumerable.hpp:294
static const ienumerable< source_t > & as_enumerable(const ienumerable< source_t > &source) noexcept
Returns the input typed as xtd::collections::generic::ienumerable <type_t>.
Definition enumerable.hpp:283
static source_t first_or_default(const ienumerable< source_t > &source, const std::function< bool(const source_t &)> &predicate, const source_t &default_value) noexcept
Returns the first element of the sequence that satisfies a condition, or a specified default value if...
Definition enumerable.hpp:585
static const ienumerable< source_t > & default_if_empty(const ienumerable< source_t > &source) noexcept
Returns the elements of the specified sequence or the type parameter's default value in a singleton c...
Definition enumerable.hpp:556
static source_t first_or_default(const ienumerable< source_t > &source, const source_t &default_value) noexcept
Returns the first element of the sequence that satisfies a condition or a default value if no such el...
Definition enumerable.hpp:604
static const auto & as_enumerable(const source_t(&array)[length]) noexcept
Returns the input typed as xtd::collections::generic::ienumerable <type_t>.
Definition enumerable.hpp:355
static const ienumerable< key_value_pair< key_t, xtd::size > > & count_by(const ienumerable< source_t > &source, const std::function< key_t(const source_t &)> &key_selector, const iequality_comparer< key_t > &key_comparer) noexcept
Returns the count of elements in the source sequence grouped by key.
Definition enumerable.hpp:529
static const ienumerable< type_t > & range(type_t count)
Generates a sequence of integral numbers within a specified range.
Definition enumerable.hpp:624
static xtd::optional< double > average(const ienumerable< xtd::optional< double > > &source) noexcept
Computes the average of a sequence of optional double values.
static const ienumerable< source_t > & append(const ienumerable< source_t > &source, const source_t &element) noexcept
Appends a value to the end of the sequence.
Definition enumerable.hpp:225
static float average(const ienumerable< float > &source)
Computes the average of a sequence of float values.
static const ienumerable< type_t > & range(type_t start, type_t count, type_t step)
Generates a sequence of integral numbers within a specified range and step.
Definition enumerable.hpp:648
static xtd::optional< double > average(const ienumerable< xtd::optional< xtd::int64 > > &source) noexcept
Computes the average of a sequence of optional xtd::int64 values.
static source_t aggregate(const ienumerable< source_t > &source, const source_t &seed, const std::function< source_t(const source_t &, const source_t &)> &func)
Applies an accumulator function over a sequence. The specified seed value is used as the initial accu...
Definition enumerable.hpp:114
static const ienumerable< source_t > & select(const ienumerable< source_t > &source, const std::function< source_t(const source_t &, xtd::size)> &selector)
Projects each element of a sequence into a new form by incorporating the element's index.
Definition enumerable.hpp:810
static const ienumerable< source_t > & concat(const ienumerable< source_t > &first, const ienumerable< source_t > &second) noexcept
Concatenates two sequences.
Definition enumerable.hpp:431
static xtd::size count(const ienumerable< source_t > &source, const std::function< bool(const source_t &)> &predicate) noexcept
Returns a number that represents how many elements in the specified sequence satisfy a condition.
Definition enumerable.hpp:490
static accumulate_t aggregate(const ienumerable< source_t > &source, const accumulate_t &seed, const std::function< accumulate_t(const source_t &, const accumulate_t &)> &func)
Applies an accumulator function over a sequence. The specified seed value is used as the initial accu...
Definition enumerable.hpp:131
static source_t first_or_default(const ienumerable< source_t > &source, const std::function< bool(const source_t &)> &predicate) noexcept
Returns the first element of the sequence that satisfies a condition or a default value if no such el...
Definition enumerable.hpp:595
static const ienumerable< source_t > & where(const ienumerable< source_t > &source, const std::function< bool(const source_t &, xtd::size)> &predicate)
Filters a sequence of values based on a predicate. Each element's index is used in the logic of the p...
Definition enumerable.hpp:855
static xtd::size count(const ienumerable< source_t > &source) noexcept
Returns the number of elements in a sequence.
Definition enumerable.hpp:474
static const auto & from(const collection_t &source) noexcept
Returns the input typed as xtd::collections::generic::ienumerable <type_t>.
Definition enumerable.hpp:705
static source_t first_or_default(const ienumerable< source_t > &source) noexcept
Returns the first element of the sequence that satisfies a condition or a default value if no such el...
Definition enumerable.hpp:612
static source_t aggregate(const ienumerable< source_t > &source, const std::function< source_t(const source_t &, const source_t &)> &func)
Applies an accumulator function over a sequence.
Definition enumerable.hpp:96
static const list< source_t > & to_list(const ienumerable< source_t > &source) noexcept
Creates a xtd::collections::generic::list <type_t> from an xtd::collections::generic::ienumerable <ty...
static xtd::size count(const ienumerable< source_t > &source, const source_t &value) noexcept
Returns the number of elements with the specified value.
Definition enumerable.hpp:500
static const auto & as_enumerable(const collection_t &source) noexcept
Returns the input typed as xtd::collections::generic::ienumerable <type_t>.
Definition enumerable.hpp:309
static const ienumerable< source_t > & from(const ienumerable< source_t > &source) noexcept
Returns the input typed as xtd::collections::generic::ienumerable <type_t>.
Definition enumerable.hpp:681
Contains xtd::linq::from methods.
generic::ienumerable< xtd::any_object > ienumerable
Exposes an enumerator, which supports a simple iteration over a non-generic collection.
Definition ienumerable.hpp:32
xtd::delegate< result_t(arguments_t... arguments)> func
Represents a delegate that has variables parameters and returns a value of the type specified by the ...
Definition func.hpp:27
@ argument
The argument is not valid.
@ argument_out_of_range
The argument is out of range.
#define static_
This keyword is use to represent a static object. A static object can't be instantiated (constructors...
Definition static.hpp:37
std::optional< type_t > optional
Represents the null_opt alias on std::nullopt_t.
Definition optional.hpp:175
long double decimal
Represents a decimal-precision floating-point number.
Definition decimal.hpp:23
size_t size
Represents a size of any object in bytes.
Definition size.hpp:23
std::type_info type
Stores information about a type.
Definition type.hpp:23
xtd::func< bool, type_t > predicate
Represents a delegate that defines a set of criteria and determines whether the specified object meet...
Definition predicate.hpp:16
@ any
Indicates that all styles except allow_binary_specifier, allow_octal_specifier and allow_hex_specifie...
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition xtd_about_box.hpp:10
Supports a simple iteration over a generic collection.
Definition enumerator.hpp:38
Defines a key/value pair that can be set or retrieved.
Definition key_value_pair.hpp:37