Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
Functional Programming

Functional-style utilities (map/filter/fold), zip utilities, ranges adapters, and parallel variants. More...

Files

file  ah-parallel.H
 Parallel functional programming operations using ThreadPool.
 
file  ah-ranges.H
 C++20 Ranges support and adaptors for Aleph-w containers.
 
file  ah-stl-functional.H
 Functional programming utilities for C++ Standard Library containers.
 
file  ah-uni-functional.H
 Unified functional programming utilities for both STL and Aleph containers.
 
file  ah-zip-utils.H
 Unified zip operations for both STL and Aleph containers.
 
file  ah-zip.H
 Zip iterators and functional operations for multiple containers.
 

Detailed Description

Functional-style utilities (map/filter/fold), zip utilities, ranges adapters, and parallel variants.

This module covers two related layers:

  1. Header-level utilities (zip views/iterators, unified functional helpers for STL/Aleph containers, ranges adapters, and parallel variants).
  2. Container methods: many Aleph-w containers (trees, lists, arrays, bit-vectors, etc.) expose functional methods directly (e.g. maps(), filter(), foldl()) via CRTP mixins.

Headers in this module

Container-level functional methods (via <tt>FunctionalMixin</tt>)

Many Aleph-w containers provide functional operations as member functions because they inherit from the CRTP mixin FunctionalMixin (see ah-dry-mixin.H).

In practice, this means that if a container provides a suitable traverse() method (directly or via TraverseMixin), it automatically gets methods such as:

Example: <tt>DynSetTree</tt> supports <tt>maps()</tt> and <tt>foldl()</tt>

See tpl_dynSetTree.H.

#include <tpl_dynSetTree.H>
#include <iostream>
using namespace Aleph;
int main()
{
DynSetTree<int, Avl_Tree> s;
for (int x : {1, 2, 3, 4, 5})
s.insert(x);
auto doubled = s.maps<int>([](int x) { return x * 2; });
int sum = s.foldl(0, [](int acc, int x) { return acc + x; });
(void) doubled;
std::cout << "sum=" << sum << "\n";
}

Example: <tt>BitArray</tt> is also a functional container

BitArray inherits from FunctionalMixin, so it also supports the same family of member functions. See bitArray.H.

Graph functional helpers

Graphs expose functional-style helpers, but they are generally specialized to node/arc traversal rather than being treated as a simple sequence container.

Common patterns include:

See tpl_graph.H and graph-dry.H.

#include <tpl_graph.H>
using namespace Aleph;
int main()
{
using Node = Graph_Node<int>;
using Arc = Graph_Arc<double>;
using G = List_Graph<Node, Arc>;
G g;
auto * a = g.insert_node(1);
auto * b = g.insert_node(2);
g.insert_arc(a, b, 1.5);
g.for_each_node([](auto * p) { (void) p; });
const auto n_gt_1 = g.count_nodes([](auto * p) { return p->get_info() > 1; });
(void) n_gt_1;
}