xtd 1.0.0
Loading...
Searching...
No Matches
enumerable.hpp
Go to the documentation of this file.
1
4#pragma once
7
9namespace xtd {
11 namespace collections {
13 namespace generic {
15 namespace extensions {
31 template<typename enumerable_t, typename source_t>
32 class enumerable {
33 public:
35
38 using enumerable_type = enumerable_t;
40 using source_type = source_t;
42 template<typename type_t>
44
46 template<typename type_t>
49
51
59 [[nodiscard]] auto aggregate(const std::function<source_t(const source_t&, const source_t&)>& func) const -> source_t {
61 }
62
69 [[nodiscard]] auto aggregate(const source_t& seed, const std::function<source_t(const source_t&, const source_t&)>& func) const -> source_t {
70 return xtd::linq::enumerable::aggregate(self(), seed, func);
71 }
72
80 template<typename accumulate_t>
81 [[nodiscard]] auto aggregate(const accumulate_t& seed, const std::function<accumulate_t(const accumulate_t&, const source_t&)>& func) const -> accumulate_t {
82 return xtd::linq::enumerable::aggregate(self(), seed, func);
83 }
84
92 [[nodiscard]] auto aggregate(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) const -> source_t {
93 return xtd::linq::enumerable::aggregate(self(), seed, func, result_selector);
94 }
95
105 template<typename result_t, typename accumulate_t>
106 [[nodiscard]] auto aggregate(const accumulate_t& seed, const std::function<accumulate_t(const accumulate_t&, const source_t&)>& func, const std::function<result_t(const accumulate_t&)>& result_selector) const -> result_t {
107 return xtd::linq::enumerable::aggregate(self(), seed, func, result_selector);
108 }
109
116 [[nodiscard]] auto all(const std::function<bool(const source_t&)>& predicate) const -> bool {
118 }
119
125 [[nodiscard]] auto any() const noexcept -> bool {
126 return xtd::linq::enumerable::any(self());
127 }
128
134 [[nodiscard]] auto any(const std::function<bool(const source_t&)>& predicate) const -> bool {
136 }
137
144 [[nodiscard]] auto append(const source_t& element) const noexcept {
145 return xtd::linq::enumerable::append(self(), element);
146 }
147
153 [[nodiscard]] auto as_enumerable() const noexcept {
155 }
156
160 [[nodiscard]] auto average() const noexcept {
161 return xtd::linq::enumerable::average(self());
162 }
163
168 template<typename result_t>
169 [[nodiscard]] auto cast() const noexcept {
171 }
172
178 [[nodiscard]] auto chunk(xtd::usize size) const {
179 return xtd::linq::enumerable::chunk(self(), size);
180 }
181
185 [[nodiscard]] auto concat(const ienumerable<source_t>& second) const noexcept {
186 return xtd::linq::enumerable::concat(self(), second);
187 }
188
192 [[nodiscard]] auto contains(const source_t& value) const noexcept -> bool {
193 return xtd::linq::enumerable::contains(self(), value);
194 }
195
200 [[nodiscard]] auto contains(const source_t& value, const xtd::collections::generic::iequality_comparer<source_t>& comparer) const noexcept -> bool {
201 return xtd::linq::enumerable::contains(self(), value, comparer);
202 }
203
209 [[nodiscard]] auto count() const noexcept -> xtd::usize {
210 return xtd::linq::enumerable::count(self());
211 }
212
219 [[nodiscard]] auto count(const std::function<bool(const source_t&)>& predicate) const noexcept -> xtd::usize {
221 }
222
226 [[nodiscard]] auto count(const source_t& value) const noexcept -> xtd::usize {
227 return xtd::linq::enumerable::count(self(), value);
228 }
229
237 template<typename key_t>
238 [[nodiscard]] auto count_by(const std::function<key_t(const source_t&)>& key_selector) const noexcept {
239 return xtd::linq::enumerable::count_by<key_t, source_t>(self(), key_selector);
240 }
241
250 template<typename key_t>
251 [[nodiscard]] auto count_by(const std::function<key_t(const source_t&)>& key_selector, const xtd::collections::generic::iequality_comparer<key_t>& key_comparer) const noexcept {
252 return xtd::linq::enumerable::count_by<key_t, source_t>(self(), key_selector, key_comparer);
253 }
254
257 [[nodiscard]] auto default_if_empty() const noexcept {
259 }
260
264 [[nodiscard]] auto default_if_empty(const source_t& default_value) const noexcept {
265 return xtd::linq::enumerable::default_if_empty(self(), default_value);
266 }
267
270 [[nodiscard]] auto distinct() const noexcept {
271 return xtd::linq::enumerable::distinct(self());
272 }
273
280 }
281
286 [[nodiscard]] auto first_or_default(const std::function<bool(const source_t&)>& predicate, const source_t& default_value) const noexcept -> source_t {
287 return xtd::linq::enumerable::first_or_default(self(), predicate, default_value);
288 }
289
292 [[nodiscard]] auto first_or_default(const std::function<bool(const source_t&)>& predicate) const noexcept -> source_t {
294 }
295
299 [[nodiscard]] auto first_or_default(const source_t default_value) const noexcept -> source_t {
300 return xtd::linq::enumerable::first_or_default(self(), default_value);
301 }
302
305 [[nodiscard]] auto first_or_default() const noexcept -> source_t {
307 }
308
309 template<typename result_t>
311 [[nodiscard]] auto max(auto&& selector) const {
312 return xtd::linq::enumerable::max<result_t, source_t>(self(), selector);
313 }
314 [[nodiscard]] auto max(auto&& selector) const requires xtd::numeric<source_t> {
315 return xtd::linq::enumerable::max(self(), selector);
316 }
317 [[nodiscard]] auto max() const requires xtd::numeric<source_t> {
318 return xtd::linq::enumerable::max(self());
319 }
320
321 template<typename result_t>
323 [[nodiscard]] auto min(auto&& selector) const {
324 return xtd::linq::enumerable::min<result_t, source_t>(self(), selector);
325 }
326 [[nodiscard]] auto min(auto&& selector) const requires xtd::numeric<source_t> {
327 return xtd::linq::enumerable::min(self(), selector);
328 }
329 [[nodiscard]] auto min() const requires xtd::numeric<source_t> {
330 return xtd::linq::enumerable::min(self());
331 }
332
336 [[nodiscard]] auto order() const {
337 return xtd::linq::enumerable::order(self());
338 }
339
345 }
346
352 [[nodiscard]] auto order_by(const std::function<source_t(const source_t&)>& key_selector) const {
353 return xtd::linq::enumerable::order_by(self(), key_selector);
354 }
355
361 template<typename key_t>
362 [[nodiscard]] auto order_by_descending(const std::function<key_t(const source_t&)>& key_selector) const {
364 }
365
371 [[nodiscard]] auto order_by_descending(const std::function<source_t(const source_t&)>& key_selector) const {
372 return xtd::linq::enumerable::order_by_descending(self(), key_selector);
373 }
374
380 template<typename key_t>
381 [[nodiscard]] auto order_by(const std::function<key_t(const source_t&)>& key_selector) const {
382 return xtd::linq::enumerable::order_by<key_t, source_t>(self(), key_selector);
383 }
384
392 [[nodiscard]] auto select(auto&& selector) const {
393 return xtd::linq::enumerable::select(self(), selector);
394 }
395
403 template<typename result_t>
404 [[nodiscard]] auto select(auto&& selector) const {
406 }
407
413 [[nodiscard]] auto to_array() const noexcept -> xtd::array<source_t>;
414
420 [[nodiscard]] auto to_list() const noexcept -> xtd::collections::generic::list<source_t>;
421
431 auto where(auto&& predicate) const {
433 }
434
435
436 private:
437 auto self() const noexcept -> const enumerable_t& {return static_cast<const enumerable_t&>(*this);}
438 };
439 }
440 }
441 }
442}
443
444#define __XTD_CORE_INTERNAL__
446#undef __XTD_CORE_INTERNAL__
447#include "../ienumerable.hpp"
Provides methods for creating, manipulating, searching, and sorting arrays, thereby serving as the ba...
Definition array.hpp:64
Provides a base class for implementations of the xtd::collections::generic::icomparer <type_t> generi...
Definition comparer.hpp:33
auto any(const std::function< bool(const source_t &)> &predicate) const -> bool
Determines whether any element of a sequence satisfies a condition.
Definition enumerable.hpp:134
auto contains(const source_t &value) const noexcept -> bool
Determines whether a sequence contains a specified element by using the default equality comparer.
Definition enumerable.hpp:192
auto first_or_default(const std::function< bool(const source_t &)> &predicate) const noexcept -> source_t
Returns the first element of the sequence that satisfies a condition or a default value if no such el...
Definition enumerable.hpp:292
auto order_by(const std::function< key_t(const source_t &)> &key_selector) const
Sorts the elements of a sequence in ascending order according to a key.
Definition enumerable.hpp:381
auto all(const std::function< bool(const source_t &)> &predicate) const -> bool
Determines whether all elements of a sequence satisfy a condition.
Definition enumerable.hpp:116
auto count(const std::function< bool(const source_t &)> &predicate) const noexcept -> xtd::usize
Returns a number that represents how many elements in the specified sequence satisfy a condition.
Definition enumerable.hpp:219
typename xtd::linq::enumerable::list< type_t > list
Represents the list value type.
Definition enumerable.hpp:47
auto count_by(const std::function< key_t(const source_t &)> &key_selector) const noexcept
Returns the count of elements in the current sequence grouped by key.
Definition enumerable.hpp:238
auto to_array() const noexcept -> xtd::array< source_t >
Creates a xtd::array <type_t> from an xtd::collections::generic::ienumerable <type_t>.
auto order() const
Sorts the elements of a sequence in ascending order.
Definition enumerable.hpp:336
auto chunk(xtd::usize size) const
Splits the elements of a sequence into chunks of size at most size.
Definition enumerable.hpp:178
auto average() const noexcept
Computes the average of a sequence of source_t values.
Definition enumerable.hpp:160
auto default_if_empty(const source_t &default_value) const noexcept
Returns the elements of the specified sequence or the specified value in a singleton collection if th...
Definition enumerable.hpp:264
auto order_by_descending(const std::function< key_t(const source_t &)> &key_selector) const
Sorts the elements of a sequence in descending order according to a key.
Definition enumerable.hpp:362
auto aggregate(const source_t &seed, const std::function< source_t(const source_t &, const source_t &)> &func) const -> source_t
Applies an accumulator function over a sequence. The specified seed value is used as the initial accu...
Definition enumerable.hpp:69
auto count_by(const std::function< key_t(const source_t &)> &key_selector, const xtd::collections::generic::iequality_comparer< key_t > &key_comparer) const noexcept
Returns the count of elements in the current sequence grouped by key.
Definition enumerable.hpp:251
auto default_if_empty() const noexcept
Returns the elements of the specified sequence or the type parameter's default value in a singleton c...
Definition enumerable.hpp:257
source_t source_type
Represents the ienumerable source type.
Definition enumerable.hpp:40
auto any() const noexcept -> bool
Determines whether a sequence contains any elements.
Definition enumerable.hpp:125
auto first_or_default(const std::function< bool(const source_t &)> &predicate, const source_t &default_value) const noexcept -> source_t
Returns the first element of the sequence that satisfies a condition, or a specified default value if...
Definition enumerable.hpp:286
auto aggregate(const std::function< source_t(const source_t &, const source_t &)> &func) const -> source_t
Applies an accumulator function over a sequence.
Definition enumerable.hpp:59
auto aggregate(const accumulate_t &seed, const std::function< accumulate_t(const accumulate_t &, const source_t &)> &func) const -> accumulate_t
Applies an accumulator function over a sequence. The specified seed value is used as the initial accu...
Definition enumerable.hpp:81
auto first_or_default(const source_t default_value) const noexcept -> source_t
Returns the first element of the sequence that satisfies a condition or a default value if no such el...
Definition enumerable.hpp:299
auto contains(const source_t &value, const xtd::collections::generic::iequality_comparer< source_t > &comparer) const noexcept -> bool
Determines whether a sequence contains a specified element by using a specified equality comparer.
Definition enumerable.hpp:200
auto to_list() const noexcept -> xtd::collections::generic::list< source_t >
Creates a xtd::collections::generic::list <type_t> from an xtd::collections::generic::ienumerable <ty...
auto select(auto &&selector) const
Projects each element of a sequence into a new form.
Definition enumerable.hpp:392
auto cast() const noexcept
Casts the elements of an xtd::collections::generic::ienumerable to the specified type.
Definition enumerable.hpp:169
auto select(auto &&selector) const
Projects each element of a sequence into a new form by incorporating the element's index.
Definition enumerable.hpp:404
auto count(const source_t &value) const noexcept -> xtd::usize
Returns the number of elements with the specified value.
Definition enumerable.hpp:226
auto order_by_descending(const std::function< source_t(const source_t &)> &key_selector) const
Sorts the elements of a sequence in descending order according to a key.
Definition enumerable.hpp:371
auto count() const noexcept -> xtd::usize
Returns the number of elements in current sequence.
Definition enumerable.hpp:209
auto distinct(const xtd::collections::generic::iequality_comparer< source_t > &comparer) const noexcept
Returns distinct elements from a sequence by using a specified xtd::collections::generic::iequality_c...
Definition enumerable.hpp:278
auto order_by(const std::function< source_t(const source_t &)> &key_selector) const
Sorts the elements of a sequence in ascending order according to a key.
Definition enumerable.hpp:352
auto aggregate(const accumulate_t &seed, const std::function< accumulate_t(const accumulate_t &, const source_t &)> &func, const std::function< result_t(const accumulate_t &)> &result_selector) const -> result_t
Applies an accumulator function over a sequence. The specified seed value is used as the initial accu...
Definition enumerable.hpp:106
auto aggregate(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) const -> source_t
Applies an accumulator function over a sequence. The specified seed value is used as the initial accu...
Definition enumerable.hpp:92
auto order(const xtd::collections::generic::icomparer< source_t > &comparer) const
Sorts the elements of a sequence in ascending order.
Definition enumerable.hpp:343
auto where(auto &&predicate) const
Filters a sequence of values based on a predicate.
Definition enumerable.hpp:431
auto append(const source_t &element) const noexcept
Appends a value to the end of the sequence.
Definition enumerable.hpp:144
auto as_enumerable() const noexcept
Returns the input typed as xtd::collections::generic::ienumerable <type_t>.
Definition enumerable.hpp:153
typename xtd::linq::enumerable::ienumerable< type_t > ienumerable
Represents the ienumerable value type.
Definition enumerable.hpp:43
auto distinct() const noexcept
Returns distinct elements from a sequence by using the default equality comparer to compare values.
Definition enumerable.hpp:270
auto first_or_default() const noexcept -> source_t
Returns the first element of the sequence that satisfies a condition or a default value if no such el...
Definition enumerable.hpp:305
enumerable_t enumerable_type
Represents the ienumerable enumerable type.
Definition enumerable.hpp:38
auto concat(const ienumerable< source_t > &second) const noexcept
Concatenates two sequences.
Definition enumerable.hpp:185
Exposes a method that compares two objects.
Definition icomparer.hpp:30
Defines methods to support the comparison of objects for equality.
Definition iequality_comparer.hpp:34
static auto 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:587
static auto append(const ienumerable< source_t > &source, const source_t &element) noexcept
Appends a value to the end of the sequence.
Definition enumerable.hpp:235
static auto any(const ienumerable< source_t > &source) noexcept -> bool
Determines whether a sequence contains any elements.
Definition enumerable.hpp:208
typename xtd::collections::generic::ienumerable< type_t > ienumerable
Represents the ienumerable value type.
Definition enumerable.hpp:83
static auto cast(const ienumerable< source_t > &source) noexcept
Casts the elements of an xtd::collections::generic::ienumerable to the specified type.
static const auto & as_enumerable(const ienumerable< source_t > &source) noexcept
Returns the input typed as xtd::collections::generic::ienumerable <type_t>.
Definition enumerable.hpp:292
static auto count(const ienumerable< source_t > &source) noexcept -> xtd::usize
Returns the number of elements in a sequence.
Definition enumerable.hpp:506
static auto aggregate(const ienumerable< source_t > &source, const std::function< source_t(const source_t &, const source_t &)> &func) -> source_t
Applies an accumulator function over a sequence.
Definition enumerable.hpp:106
typename xtd::collections::generic::list< type_t > list
Represents the list value type.
Definition enumerable.hpp:87
static auto all(const ienumerable< source_t > &source, const std::function< bool(const source_t &)> &predicate) -> bool
Determines whether all elements of a sequence satisfy a condition.
Definition enumerable.hpp:193
static auto first_or_default(const ienumerable< source_t > &source, const std::function< bool(const source_t &)> &predicate, const source_t &default_value) noexcept -> source_t
Returns the first element of the sequence that satisfies a condition, or a specified default value if...
Definition enumerable.hpp:640
static auto average(const ienumerable< xtd::decimal > &source) -> xtd::decimal
Computes the average of a sequence of xtd::decimal values.
static auto concat(const ienumerable< source_t > &first, const ienumerable< source_t > &second) noexcept
Concatenates two sequences.
Definition enumerable.hpp:464
static auto order_by_descending(const ienumerable< source_t > &source, const std::function< key_t(const source_t &)> &key_selector)
Sorts the elements of a sequence in descending order according to a key.
Definition enumerable.hpp:879
static auto distinct(const ienumerable< source_t > &source) noexcept
Returns distinct elements from a sequence by using the default equality comparer to compare values.
Definition enumerable.hpp:612
static auto contains(const ienumerable< source_t > &source, const source_t &value) noexcept -> bool
Determines whether a sequence contains a specified element by using the default equality comparer.
Definition enumerable.hpp:479
static auto order_by(const ienumerable< source_t > &source, const std::function< key_t(const source_t &)> &key_selector)
Sorts the elements of a sequence in ascending order according to a key.
Definition enumerable.hpp:849
static auto order(const ienumerable< source_t > &source)
Sorts the elements of a sequence in ascending order.
Definition enumerable.hpp:826
static auto where(const ienumerable< source_t > &source, auto &&predicate)
Filters a sequence of values based on a predicate.
Definition enumerable.hpp:1013
static auto 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:546
static auto chunk(const ienumerable< source_t > &source, xtd::usize size)
Splits the elements of a sequence into chunks of size at most size.
static auto select(const ienumerable< source_t > &source, auto &&selector)
Projects each element of a sequence into a new form.
Definition enumerable.hpp:954
Definition enumerable.hpp:17
Definition numeric.hpp:12
Contains foreach_ keyword.
Contains xtd::collections::generic::ienumerable <type_t> interface.
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
std::size_t usize
Represents an unsigned size of any object in bytes.
Definition usize.hpp:22
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
Contains xtd::linq::enumerable <type_t> class.
The xtd::extensions namespace contains interface extensions.
Definition collection_common.hpp:14
The xtd::collections::generic namespace contains interfaces and classes that define generic collectio...
Definition comparer.hpp:16
The xtd::collections namespace contains interfaces and classes that define various collections of obj...
Definition any_pair.hpp:10
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition abstract_object.hpp:8
constexpr auto size() const noexcept -> size_type
Returns the number of elements.
Definition read_only_span.hpp:217