148#include <tclap/CmdLine.h>
155using namespace Aleph;
163 cout <<
"\n" << string(60,
'=') <<
"\n";
165 cout << string(60,
'=') <<
"\n\n";
173template <
typename Container>
176 cout << label <<
": [";
178 for (
const auto& x : c)
187template <
typename Container>
190 cout << label <<
": [";
192 for (
auto it = c.get_it(); it.has_curr(); it.next())
195 cout << it.get_curr();
209 cout <<
"The key insight: ONE function works with ALL container types!\n\n";
212 vector<int>
stl_vec = {1, 2, 3, 4, 5};
251 vector<int>
numbers = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
303 return a > b ? a : b;
312 return a.empty() ? b : a +
" " + b;
331 vector<int>
mixed = {-1, 2, -3, 4, 5};
342 cout <<
"All positive in all_positive? "
344 cout <<
"All positive in mixed? "
349 cout <<
"Exists positive in mixed? "
351 cout <<
"Exists positive in all_negative? "
356 cout <<
"None positive in all_negative? "
385 if (first)
cout <<
"First: " << *first <<
endl;
386 if (last)
cout <<
"Last: " << *last <<
endl;
399 return s.length() > 8;
417 vector<int>
nums = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
505 print_stl(
"map(*10) -> filter(even) -> vector", result);
519 vector<int>
quantities = {100, 250, 180, 120, 200};
522 cout <<
"prices (DynList): [25.0, 8.0, 12.0, 15.0, 10.0]" <<
endl;
536 cout <<
"Revenue by product:\n";
579 "Unified functional programming example for Aleph-w.\n"
580 "Same functions work with STL and Aleph containers.",
586 "Run only specific section: unified, map, fold, predicates, "
587 "access, slicing, statistics, conversion, practical, or 'all'",
588 false,
"all",
"section",
cmd
596 cout <<
"============================================================\n";
597 cout <<
" ALEPH-W UNIFIED FUNCTIONAL PROGRAMMING EXAMPLE\n";
598 cout <<
" (Same API for STL and Aleph containers!)\n";
599 cout <<
"============================================================\n";
628 cout <<
"\n" << string(60,
'=') <<
"\n";
629 cout <<
"Unified functional programming demo completed!\n";
630 cout << string(60,
'=') <<
"\n\n";
634 catch (TCLAP::ArgException& e)
636 cerr <<
"Error: " << e.error() <<
" for argument " << e.argId() <<
endl;
641 cerr <<
"Error: " << e.what() <<
endl;
Unified functional programming utilities for both STL and Aleph containers.
Dynamic singly linked list with functional programming support.
T & get_first() const
Return the first item of the list.
size_t size() const noexcept
Count the number of elements of the list.
Singly linked list implementations with head-tail access.
Main namespace for Aleph-w library functions.
bool uni_none(Pred &&pred, const Container &c)
Check if no element satisfies predicate.
auto uni_filter(Pred &&pred, const Container &c)
Filter elements satisfying predicate.
auto uni_nth(size_t n, const Container &c)
Get n-th element.
size_t uni_length(const Container &c)
Get container length.
auto uni_drop_while(Pred &&pred, const Container &c)
Drop elements while predicate is true, return the rest.
auto uni_product(const Container &c)
Product of all elements.
auto uni_find(Pred &&pred, const Container &c)
Find first element satisfying predicate.
bool uni_mem(const T &target, const Container &c)
Check if element exists in container (mem in ML).
T product(const Container &container, const T &init=T{1})
Compute product of all elements.
auto uni_filteri(Pred &&pred, const Container &c)
Filter with index (filteri in ML).
auto uni_map(Op &&op, const Container &c)
Map operation - transform each element.
auto uni_last(const Container &c)
Get last element.
auto uni_min_max(const Container &c)
Get both min and max in a single pass.
auto uni_min(const Container &c)
Get minimum element.
size_t uni_count(Pred &&pred, const Container &c)
Count elements satisfying predicate.
std::string to_string(const time_t t, const std::string &format)
Format a time_t value into a string using format.
T uni_foldl(T init, Op &&op, const Container &c)
Left fold (foldl) - reduce from left to right.
auto uni_drop(size_t n, const Container &c)
Drop first n elements, return the rest.
auto uni_max(const Container &c)
Get maximum element.
auto uni_take_while(Pred &&pred, const Container &c)
Take elements while predicate is true.
bool uni_all(Pred &&pred, const Container &c)
Check if all elements satisfy predicate.
auto uni_first(const Container &c)
Get first element.
auto uni_partition(Pred &&pred, const Container &c)
Partition elements by predicate.
auto uni_to_vector(const Container &c)
Convert container to std::vector.
auto uni_mapi(Op &&op, const Container &c)
Map with index (mapi in ML).
bool uni_any(Pred &&pred, const Container &c)
Alias for uni_exists.
auto uni_take(size_t n, const Container &c)
Take first n elements.
auto uni_sum(const Container &c)
Sum all elements.
bool uni_exists(Pred &&pred, const Container &c)
Check if any element satisfies predicate.
DynList< T > maps(const C &c, Op op)
Classic map operation.
Itor::difference_type count(const Itor &beg, const Itor &end, const T &value)
Count elements equal to a value.
T sum(const Container &container, const T &init=T{})
Compute sum of all elements.
Lazy and scalable dynamic array implementation.
void print_subsection(const string &title)
void print_stl(const string &label, const Container &c)
void print_section(const string &title)
void print_aleph(const string &label, const Container &c)