Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
ah-uni-functional.H File Reference

Unified functional programming utilities for both STL and Aleph containers. More...

#include <type_traits>
#include <vector>
#include <optional>
#include <functional>
#include <algorithm>
#include <utility>
#include <tuple>
#include <iterator>
Include dependency graph for ah-uni-functional.H:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  Aleph::uni_functional_detail::has_stl_iterator< T, typename >
 
struct  Aleph::uni_functional_detail::has_stl_iterator< T, std::void_t< decltype(std::declval< const T & >().begin()), decltype(std::declval< const T & >().end()), typename T::value_type > >
 
struct  Aleph::uni_functional_detail::has_aleph_iterator< T, typename >
 
struct  Aleph::uni_functional_detail::has_aleph_iterator< T, std::void_t< typename T::Iterator, typename T::Item_Type, decltype(std::declval< typename T::Iterator >().has_curr()), decltype(std::declval< typename T::Iterator >().get_curr()), decltype(std::declval< typename T::Iterator >().next()) > >
 
struct  Aleph::uni_functional_detail::has_reverse_iterator< T, typename >
 
struct  Aleph::uni_functional_detail::has_reverse_iterator< T, std::void_t< decltype(std::declval< const T & >().rbegin()), decltype(std::declval< const T & >().rend()) > >
 
struct  Aleph::uni_functional_detail::container_value_type< T, std::enable_if_t< has_stl_iterator< T >::value > >
 
struct  Aleph::uni_functional_detail::container_value_type< T, std::enable_if_t< has_aleph_iterator< T >::value and not has_stl_iterator< T >::value > >
 

Namespaces

namespace  Aleph
 Main namespace for Aleph-w library functions.
 
namespace  Aleph::uni_functional_detail
 

Typedefs

template<typename T >
using Aleph::uni_functional_detail::value_t = typename container_value_type< std::decay_t< T > >::type
 

Functions

template<typename Op , typename Container >
void Aleph::uni_for_each (Op &&op, const Container &c)
 Apply operation to each element (for_each).
 
template<typename Op , typename Container >
void Aleph::uni_for_each_indexed (Op &&op, const Container &c)
 Apply operation to each element with index.
 
template<typename Op , typename Container >
auto Aleph::uni_map (Op &&op, const Container &c)
 Map operation - transform each element.
 
template<typename Op , typename Container >
auto Aleph::uni_mapi (Op &&op, const Container &c)
 Map with index (mapi in ML).
 
template<typename Pred , typename Container >
auto Aleph::uni_filter (Pred &&pred, const Container &c)
 Filter elements satisfying predicate.
 
template<typename Pred , typename Container >
auto Aleph::uni_filteri (Pred &&pred, const Container &c)
 Filter with index (filteri in ML).
 
template<typename T , typename Op , typename Container >
T Aleph::uni_foldl (T init, Op &&op, const Container &c)
 Left fold (foldl) - reduce from left to right.
 
template<typename T , typename Op , typename Container >
T Aleph::uni_reduce (T init, Op &&op, const Container &c)
 Alias for uni_foldl.
 
template<typename T , typename Op , typename Container >
std::vector< TAleph::uni_scan_left (T init, Op &&op, const Container &c)
 Scan left - fold with all intermediate results.
 
template<typename Pred , typename Container >
bool Aleph::uni_all (Pred &&pred, const Container &c)
 Check if all elements satisfy predicate.
 
template<typename Pred , typename Container >
bool Aleph::uni_exists (Pred &&pred, const Container &c)
 Check if any element satisfies predicate.
 
template<typename Pred , typename Container >
bool Aleph::uni_any (Pred &&pred, const Container &c)
 Alias for uni_exists.
 
template<typename Pred , typename Container >
bool Aleph::uni_none (Pred &&pred, const Container &c)
 Check if no element satisfies predicate.
 
template<typename Pred , typename Container >
auto Aleph::uni_find (Pred &&pred, const Container &c)
 Find first element satisfying predicate.
 
template<typename Pred , typename Container >
std::optional< size_tAleph::uni_find_index (Pred &&pred, const Container &c)
 Find index of first element satisfying predicate.
 
template<typename Op , typename Container >
auto Aleph::uni_find_mapi (Op &&op, const Container &c)
 Find and map with index (find_mapi in ML).
 
template<typename T , typename Container >
bool Aleph::uni_mem (const T &target, const Container &c)
 Check if element exists in container (mem in ML).
 
template<typename Pred , typename Container >
size_t Aleph::uni_count (Pred &&pred, const Container &c)
 Count elements satisfying predicate.
 
template<typename Container >
size_t Aleph::uni_length (const Container &c)
 Get container length.
 
template<typename Container >
auto Aleph::uni_take (size_t n, const Container &c)
 Take first n elements.
 
template<typename Container >
auto Aleph::uni_drop (size_t n, const Container &c)
 Drop first n elements, return the rest.
 
template<typename Pred , typename Container >
auto Aleph::uni_take_while (Pred &&pred, const Container &c)
 Take elements while predicate is true.
 
template<typename Pred , typename Container >
auto Aleph::uni_drop_while (Pred &&pred, const Container &c)
 Drop elements while predicate is true, return the rest.
 
template<typename Container >
auto Aleph::uni_first (const Container &c)
 Get first element.
 
template<typename Container >
auto Aleph::uni_last (const Container &c)
 Get last element.
 
template<typename Container >
auto Aleph::uni_nth (size_t n, const Container &c)
 Get n-th element.
 
template<typename Container >
auto Aleph::uni_min (const Container &c)
 Get minimum element.
 
template<typename Container >
auto Aleph::uni_max (const Container &c)
 Get maximum element.
 
template<typename Container >
auto Aleph::uni_min_max (const Container &c)
 Get both min and max in a single pass.
 
template<typename Container >
auto Aleph::uni_sum (const Container &c)
 Sum all elements.
 
template<typename Container >
auto Aleph::uni_product (const Container &c)
 Product of all elements.
 
template<typename Pred , typename Container >
auto Aleph::uni_partition (Pred &&pred, const Container &c)
 Partition elements by predicate.
 
template<typename Container1 , typename Container2 >
auto Aleph::uni_concat (const Container1 &c1, const Container2 &c2)
 Concatenate two containers.
 
template<typename Container >
auto Aleph::uni_flatten (const Container &c)
 Flatten a container of containers.
 
template<typename Op , typename Container >
auto Aleph::uni_flat_map (Op &&op, const Container &c)
 Flat map - map then flatten.
 
template<typename Container >
auto Aleph::uni_distinct (const Container &c)
 Remove all duplicates (keeps first occurrence).
 
template<typename Key , typename Container >
auto Aleph::uni_group_by (Key &&key, const Container &c)
 Group elements by key function.
 
template<typename Container >
auto Aleph::uni_tally (const Container &c)
 Count occurrences of each element (frequency count).
 
template<typename Container >
auto Aleph::uni_to_vector (const Container &c)
 Convert container to std::vector.
 
template<typename Container1 , typename Container2 >
bool Aleph::uni_equal (const Container1 &c1, const Container2 &c2)
 Check equality of two containers.
 
template<typename Container1 , typename Container2 >
int Aleph::uni_compare (const Container1 &c1, const Container2 &c2)
 Compare two containers lexicographically.
 

Variables

template<typename T >
constexpr bool Aleph::uni_functional_detail::is_stl_container_v = has_stl_iterator<std::decay_t<T>>::value
 
template<typename T >
constexpr bool Aleph::uni_functional_detail::is_aleph_only_v
 

Detailed Description

Unified functional programming utilities for both STL and Aleph containers.

This header provides functional programming operations that work seamlessly with any container type:

  • STL containers: std::vector, std::list, std::deque, std::set, etc.
  • Aleph containers: DynList, DynArray, DynDlist, DynSetTree, etc.

The implementation uses type traits to automatically detect the container type and apply the appropriate iteration method.

Usage Example:

#include <htlist.H>
#include <vector>
std::vector<int> stl_vec = {1, 2, 3, 4, 5};
DynList<int> aleph_list = {10, 20, 30, 40, 50};
// Same function works with both!
auto stl_squares = uni_map([](int x) { return x * x; }, stl_vec);
auto aleph_squares = uni_map([](int x) { return x * x; }, aleph_list);
int stl_sum = uni_foldl(0, std::plus<int>{}, stl_vec);
int aleph_sum = uni_foldl(0, std::plus<int>{}, aleph_list);
Unified functional programming utilities for both STL and Aleph containers.
Singly linked list implementations with head-tail access.
auto uni_map(Op &&op, const Container &c)
Map operation - transform each element.
auto stl_sum(const Container &c)
Sum all elements.
T uni_foldl(T init, Op &&op, const Container &c)
Left fold (foldl) - reduce from left to right.
Note
foldr is only available for STL containers with reverse iterators.
Author
Leandro Rabindranath Leon

Definition in file ah-uni-functional.H.