Skip to content

Commit

Permalink
Review examples
Browse files Browse the repository at this point in the history
  • Loading branch information
gammasoft71 committed Dec 22, 2024
1 parent edc98f1 commit 7b96d7c
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 18 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
#include <xtd/linq/enumerable>
#include <xtd/console>
#include <xtd/string>

using namespace xtd;
using namespace xtd::linq;

auto main() -> int {
auto sentence = "the quick brown fox jumps over the lazy dog"_s;
Expand All @@ -11,7 +10,7 @@ auto main() -> int {
auto words = sentence.split(' ');

// Prepend each word to the beginning of the new sentence to reverse the word order.
auto reversed = enumerable::aggregate(words, [](const string& working_sentence, const string& next) {
auto reversed = words.aggregate([](const string& working_sentence, const string& next) {
return next + " " + working_sentence;
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
#include <xtd/linq/enumerable>
#include <xtd/array>
#include <xtd/console>

using namespace xtd;
using namespace xtd::linq;

auto main() -> int {
auto ints = array {4, 8, 8, 3, 9, 0, 7, 8, 2};

// Count the even numbers in the array, using a seed value of 0.
auto num_even = enumerable::aggregate(ints, 0, [](int total, int next) {
auto num_even = ints.aggregate(0, [](int total, int next) {
return next % 2 == 0 ? total + 1 : total;
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
#include <xtd/linq/enumerable>
#include <xtd/array>
#include <xtd/console>

using namespace xtd;
using namespace xtd::linq;

auto main() -> int {
auto fruits = array {"apple"_s, "mango"_s, "orange"_s, "passionfruit"_s, "grape"_s};

// Determine whether any string in the array is longer than "banana".
auto longest_name =
enumerable::aggregate(fruits, "bananas"_s,
fruits.aggregate("bananas"_s,
[](const string& longest, const string& next) {return next.length() > longest.length() ? next : longest;},
// Return the final result as an upper case string.
[](const string& fruit) {return fruit.to_upper();});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
#include <xtd/linq/enumerable>
#include <xtd/array>
#include <xtd/console>

using namespace xtd;
using namespace xtd::linq;

auto main() -> int {
struct pet : public object {
Expand All @@ -21,7 +20,7 @@ auto main() -> int {
};

// Determine whether all pet names in the array start with 'B'.
bool all_start_with_b = enumerable::all(pets, [](const pet& pet) {
bool all_start_with_b = pets.all([](const pet& pet) {
return pet.name.starts_with("B");
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
#include <xtd/collections/generic/list>
#include <xtd/linq/enumerable>
#include <xtd/console>

using namespace xtd;
using namespace xtd::collections::generic;
using namespace xtd::linq;

auto main() -> int {
auto numbers = list {1, 2};
auto has_elements = enumerable::any(numbers);
auto has_elements = numbers.any();

console::write_line("The list {0} empty.", has_elements ? "is not" : "is");
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
#include <xtd/linq/enumerable>
#include <xtd/array>
#include <xtd/console>

using namespace xtd;
using namespace xtd::linq;

auto main() -> int {
struct pet : public object {
Expand All @@ -22,7 +21,7 @@ auto main() -> int {
};

// Determine whether all pet names in the array start with 'B'.
bool unvaccinated = enumerable::any(pets, [](const pet& pet) {
bool unvaccinated = pets.any([](const pet& pet) {
return pet.age > 1 && !pet.vaccinated;
});

Expand Down

0 comments on commit 7b96d7c

Please sign in to comment.