xtd 1.0.0
Loading...
Searching...
No Matches
enumerable_aggregate6.cpp

demonstrates how to use xtd::linq::enumerable::aggregate method.

#include <xtd/xtd>
auto main() -> int {
auto fruits = std::vector<std::string> {"apple", "mango", "orange", "passionfruit", "grape"};
// Determine whether any string in the array is longer than "banana".
auto longest_name =
from(fruits).aggregate("bananas",
[](auto&& longest, auto&& next) {return next.size() > longest.size() ? next : longest;},
// Return the final result as an upper case string.
[](auto&& fruit) {return string {fruit}.to_upper();});
console::write_line("The fruit with the longest name is {}", longest_name);
}
// This code produces the following output :
//
// The fruit with the longest name is PASSIONFRUIT