Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
Aleph::FunctionalMixin< Derived, Type > Class Template Reference

CRTP Mixin providing functional programming operations. More...

#include <ah-dry-mixin.H>

Inheritance diagram for Aleph::FunctionalMixin< Derived, Type >:
[legend]

Public Member Functions

template<class Operation >
auto for_each (Operation &operation) const -> decltype(self())
 Apply an operation to each element (read-only).
 
template<class Operation >
auto for_each (Operation &operation) -> decltype(self())
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
template<class Operation >
auto for_each (Operation &&operation=Operation()) const -> decltype(self())
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
template<class Operation >
auto for_each (Operation &&operation=Operation()) -> decltype(self())
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
template<class Operation >
auto mutable_for_each (Operation &operation) -> decltype(self())
 Apply an operation to each element (mutable).
 
template<class Operation >
auto mutable_for_each (Operation &&operation=Operation()) -> decltype(self())
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
template<class Operation >
bool all (Operation &operation) const
 Test if all elements satisfy a predicate.
 
template<class Operation >
bool all (Operation &&operation=Operation()) const
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
template<class Operation >
bool forall (Operation &operation) const
 Alias for all().
 
template<class Operation >
bool forall (Operation &&operation=Operation()) const
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
template<class Operation >
bool exists (Operation &operation) const
 Test if any element satisfies a predicate.
 
template<class Operation >
bool exists (Operation &&operation=Operation()) const
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
template<typename __Type = Type, template< typename > class Container = Aleph::DynList, class Operation = Dft_Map_Op<Type, __Type>>
Container< __Type > maps (Operation &operation) const
 Transform elements using a mapping function.
 
template<typename __Type = Type, template< typename > class Container = Aleph::DynList, class Operation = Dft_Map_Op<Type, __Type>>
Container< __Type > maps (Operation &&operation=Operation()) const
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
template<typename __Type = Type>
__Type foldl (const __Type &init, std::function< __Type(const __Type &, const Type &)> operation) const
 Left fold (reduce) with initial value.
 
template<typename __Type = Type>
__Type fold_left (std::function< __Type(const __Type &, const Type &)> operation, const __Type &init) const
 Left fold with operation first (alternative signature).
 
template<class Operation >
Type fold (const Type &init, Operation &operation) const
 Simple fold with same type for accumulator and elements.
 
template<class Operation >
Type fold (const Type &init, Operation &&operation=Operation()) const
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
template<class Operation >
DynList< Typefilter (Operation &operation) const
 Filter elements by a predicate.
 
template<class Operation >
DynList< Typefilter (Operation &&operation=Operation()) const
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
template<class Operation >
DynList< std::tuple< Type, size_t > > pfilter (Operation &operation) const
 Filter with position information.
 
template<class Operation >
DynList< std::tuple< Type, size_t > > pfilter (Operation &&operation=Operation()) const
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
template<class Operation >
std::pair< DynList< Type >, DynList< Type > > partition (Operation &op) const
 Partition elements by a predicate.
 
template<class Operation >
std::pair< DynList< Type >, DynList< Type > > partition (Operation &&op=Operation()) const
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
template<class Operation >
std::tuple< DynList< Type >, DynList< Type > > tpartition (Operation &op) const
 Partition returning tuple instead of pair.
 
template<class Operation >
std::tuple< DynList< Type >, DynList< Type > > tpartition (Operation &&op=Operation()) const
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
size_t length () const noexcept
 Count the number of elements.
 
template<template< typename > class Container = Aleph::DynList>
Container< Typerev () const
 Create a reversed copy.
 
template<template< typename > class Container = Aleph::DynList>
Container< Typetake (const size_t n) const
 Take the first n elements.
 
template<template< typename > class Container = Aleph::DynList>
Container< Typedrop (const size_t n) const
 Skip the first n elements.
 
Type sum (const Type &init=Type{}) const
 Compute the sum of all elements.
 
Type product (const Type &init) const
 Compute the product of all elements.
 
const Typemin () const
 Find the minimum element.
 
const Typemax () const
 Find the maximum element.
 
template<class Compare >
const Typemin_by (Compare cmp) const
 Find the minimum element using a custom comparator.
 
template<class Compare >
const Typemax_by (Compare cmp) const
 Find the maximum element using a custom comparator.
 
bool has_value (const Type &val) const
 Check if container has a value.
 
template<class Predicate >
bool none (Predicate &pred) const
 Check if no element satisfies a predicate.
 
template<class Predicate >
bool none (Predicate &&pred) const
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
template<class Predicate >
size_t count_if (Predicate pred) const
 Count elements satisfying a predicate.
 
const Typefirst () const
 Get the first element.
 
Type first_or (const Type &default_val) const
 Get the first element or a default value.
 
const Typelast () const
 Get the last element.
 
Type last_or (const Type &default_val) const
 Get the last element or a default value.
 
template<template< typename > class Container = Aleph::DynList>
Container< std::pair< size_t, Type > > enumerate () const
 Enumerate elements with their indices.
 
template<class Predicate >
size_t find_index (Predicate pred) const
 Find the index of the first element satisfying a predicate.
 
size_t index_of (const Type &val) const
 Find the index of a specific value.
 
template<template< typename > class Container = Aleph::DynList>
requires requires(Type a, Type b) { { a == b } -> std::convertible_to<bool>; }
Container< Typeunique () const
 Remove consecutive duplicate elements.
 
template<template< typename > class Container = Aleph::DynList, class EqPred >
Container< Typeunique_by (EqPred eq) const
 Remove consecutive duplicates using a custom equality predicate.
 
template<template< typename > class Container = Aleph::DynList>
Container< Typeintersperse (const Type &sep) const
 Intersperse a separator between elements.
 
template<template< typename > class Container = Aleph::DynList>
Container< Container< Type > > chunk (size_t n) const
 Split into chunks of fixed size.
 
template<template< typename > class Container = Aleph::DynList>
Container< Container< Type > > sliding (size_t size, size_t step=1) const
 Create sliding windows of fixed size.
 
std::vector< Typeto_vector () const
 Convert to std::vector.
 
template<typename DynListType = DynList<Type>>
DynListType to_dynlist () const
 Convert container to DynList.
 
template<typename StringType = std::string>
requires requires(Type a) { std::to_string(a); }
StringType join (const StringType &sep=StringType{", "}) const
 Join elements into a string with separator.
 
std::string join_str (const std::string &sep=", ") const
 Join string elements with separator.
 
template<class Other , template< typename > class Container = Aleph::DynList>
Container< std::pair< Type, typename Other::Item_Type > > zip_with (const Other &other) const
 Zip with another container.
 

Protected Member Functions

const Derivedself () const noexcept
 
Derivedself () noexcept
 

Detailed Description

template<typename Derived, typename Type>
class Aleph::FunctionalMixin< Derived, Type >

CRTP Mixin providing functional programming operations.

This mixin adds functional programming methods to containers:

Template Parameters
DerivedThe derived container class (CRTP pattern).
TypeThe element type stored in the container.
Requirements
The derived class must provide:
Author
Leandro Rabindranath León

Definition at line 457 of file ah-dry-mixin.H.

Member Function Documentation

◆ all() [1/2]

template<typename Derived , typename Type >
template<class Operation >
bool Aleph::FunctionalMixin< Derived, Type >::all ( Operation &&  operation = Operation()) const
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 592 of file ah-dry-mixin.H.

References Aleph::FunctionalMixin< Derived, Type >::maps().

◆ all() [2/2]

template<typename Derived , typename Type >
template<class Operation >
bool Aleph::FunctionalMixin< Derived, Type >::all ( Operation operation) const
inline

Test if all elements satisfy a predicate.

Returns true if the predicate returns true for every element. Returns true for empty containers (vacuous truth).

Template Parameters
OperationCallable with signature bool(const Type&).
Parameters
operationPredicate to test.
Returns
true if all elements satisfy the predicate.
Complexity
O(n) worst case, but stops early on first false.
Example
DynList<int> list = {2, 4, 6, 8};
bool allEven = list.all([](int x) { return x % 2 == 0; }); // true
Dynamic singly linked list with functional programming support.
Definition htlist.H:1423
Container< __Type > maps(Operation &operation) const
Transform elements using a mapping function.
bool all(Operation &operation) const
Check if all the elements of container satisfy a condition.
Definition ah-dry.H:816

Definition at line 585 of file ah-dry-mixin.H.

References Aleph::FunctionalMixin< Derived, Type >::maps(), and Aleph::FunctionalMixin< Derived, Type >::self().

Referenced by Aleph::FunctionalMixin< Derived, Type >::sliding(), TEST(), TEST(), and TEST().

◆ chunk()

template<typename Derived , typename Type >
template<template< typename > class Container = Aleph::DynList>
Container< Container< Type > > Aleph::FunctionalMixin< Derived, Type >::chunk ( size_t  n) const
inline

Split into chunks of fixed size.

Template Parameters
ContainerResult container type (default: DynList).
Parameters
nChunk size.
Returns
Container of containers, each with at most n elements.
Complexity
O(n).
Example
DynList<int> list = {1, 2, 3, 4, 5};
auto chunks = list.chunk(2); // {{1,2}, {3,4}, {5}}

Definition at line 1589 of file ah-dry-mixin.H.

References Aleph::count(), Aleph::FunctionalMixin< Derived, Type >::for_each(), and Aleph::FunctionalMixin< Derived, Type >::maps().

Referenced by TEST(), TEST(), TEST(), TEST(), TEST(), and TEST().

◆ count_if()

template<typename Derived , typename Type >
template<class Predicate >
size_t Aleph::FunctionalMixin< Derived, Type >::count_if ( Predicate  pred) const
inline

Count elements satisfying a predicate.

Template Parameters
PredicatePredicate type.
Parameters
predPredicate function.
Returns
Number of elements for which pred returns true.
Complexity
O(n).
Example
DynList<int> list = {1, 2, 3, 4, 5};
auto evens = list.count_if([](int x) { return x % 2 == 0; }); // 2

Definition at line 1276 of file ah-dry-mixin.H.

References Aleph::count(), Aleph::FunctionalMixin< Derived, Type >::for_each(), Aleph::FunctionalMixin< Derived, Type >::maps(), and pred.

Referenced by TEST(), TEST(), TEST(), and TEST().

◆ drop()

template<typename Derived , typename Type >
template<template< typename > class Container = Aleph::DynList>
Container< Type > Aleph::FunctionalMixin< Derived, Type >::drop ( const size_t  n) const
inline

Skip the first n elements.

Template Parameters
ContainerResult container type (default: DynList).
Parameters
nNumber of elements to skip.
Returns
New container with elements after the first n.
Complexity
O(size()).
Example
DynList<int> list = {1, 2, 3, 4, 5};
auto after2 = list.drop(2); // {3, 4, 5}
auto empty = list.drop(100); // {}
Aleph::DynList< T > drop(const size_t n) const
Drop the first n elements seen in the container during its traversal.
Definition ah-dry.H:1467

Definition at line 1011 of file ah-dry-mixin.H.

References Aleph::FunctionalMixin< Derived, Type >::maps(), and Aleph::FunctionalMixin< Derived, Type >::self().

Referenced by TEST().

◆ enumerate()

template<typename Derived , typename Type >
template<template< typename > class Container = Aleph::DynList>
Container< std::pair< size_t, Type > > Aleph::FunctionalMixin< Derived, Type >::enumerate ( ) const
inline

Enumerate elements with their indices.

Template Parameters
ContainerResult container type (default: DynList).
Returns
Container of pairs (index, element).
Complexity
O(n).
Example
DynList<std::string> list = {"a", "b", "c"};
for (auto [idx, val] : list.enumerate())
std::cout << idx << ": " << val << "\n";
// Output: 0: a, 1: b, 2: c
Container< std::pair< size_t, Type > > enumerate() const
Enumerate elements with their indices.
STL namespace.

Definition at line 1399 of file ah-dry-mixin.H.

References Aleph::FunctionalMixin< Derived, Type >::for_each(), and Aleph::FunctionalMixin< Derived, Type >::maps().

Referenced by TEST(), TEST(), TEST(), TEST(), and TEST().

◆ exists() [1/2]

template<typename Derived , typename Type >
template<class Operation >
bool Aleph::FunctionalMixin< Derived, Type >::exists ( Operation &&  operation = Operation()) const
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 642 of file ah-dry-mixin.H.

References Aleph::FunctionalMixin< Derived, Type >::maps().

◆ exists() [2/2]

template<typename Derived , typename Type >
template<class Operation >
bool Aleph::FunctionalMixin< Derived, Type >::exists ( Operation operation) const
inline

Test if any element satisfies a predicate.

Returns true if the predicate returns true for at least one element. Returns false for empty containers.

Template Parameters
OperationCallable with signature bool(const Type&).
Parameters
operationPredicate to test.
Returns
true if at least one element satisfies the predicate.
Complexity
O(n) worst case, but stops early on first true.
Example
DynList<int> list = {1, 3, 5, 6, 7};
bool hasEven = list.exists([](int x) { return x % 2 == 0; }); // true (6)
bool exists(Operation &op) const
Test for existence in the container of an element satisfying a criteria.
Definition ah-dry.H:846

Definition at line 632 of file ah-dry-mixin.H.

References Aleph::FunctionalMixin< Derived, Type >::maps(), and Aleph::FunctionalMixin< Derived, Type >::self().

Referenced by Aleph::FunctionalMixin< Derived, Type >::none(), Aleph::FunctionalMixin< Derived, Type >::none(), TEST(), and TEST().

◆ filter() [1/2]

template<typename Derived , typename Type >
template<class Operation >
DynList< Type > Aleph::FunctionalMixin< Derived, Type >::filter ( Operation &&  operation = Operation()) const
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 811 of file ah-dry-mixin.H.

References Aleph::FunctionalMixin< Derived, Type >::maps().

◆ filter() [2/2]

template<typename Derived , typename Type >
template<class Operation >
DynList< Type > Aleph::FunctionalMixin< Derived, Type >::filter ( Operation operation) const
inline

Filter elements by a predicate.

Creates a new list containing only elements for which the predicate returns true.

Template Parameters
OperationCallable with signature bool(const Type&).
Parameters
operationPredicate function.
Returns
DynList containing only matching elements.
Complexity
O(n).
Example
DynList<int> nums = {1, 2, 3, 4, 5, 6};
auto evens = nums.filter([](int x) { return x % 2 == 0; });
// evens = {2, 4, 6}
Aleph::DynList< T > filter(Operation &operation) const
Filter the elements of a container according to a matching criteria.
Definition ah-dry.H:1135

Definition at line 798 of file ah-dry-mixin.H.

References Aleph::FunctionalMixin< Derived, Type >::for_each(), and Aleph::FunctionalMixin< Derived, Type >::maps().

Referenced by TEST(), TEST(), TEST(), TEST(), and TEST().

◆ find_index()

template<typename Derived , typename Type >
template<class Predicate >
size_t Aleph::FunctionalMixin< Derived, Type >::find_index ( Predicate  pred) const
inline

Find the index of the first element satisfying a predicate.

Template Parameters
PredicatePredicate type.
Parameters
predPredicate function.
Returns
Index of first matching element, or size_t(-1) if not found.
Complexity
O(n) worst case.
Example
DynList<int> list = {1, 2, 3, 4, 5};
auto idx = list.find_index([](int x) { return x > 3; }); // 3
size_t find_index(Operation &operation) const noexcept(operation_is_noexcept< Operation >())
Find the position of an item in the container according to a searching criteria.
Definition ah-dry.H:393

Definition at line 1426 of file ah-dry-mixin.H.

References Aleph::FunctionalMixin< Derived, Type >::maps(), pred, and Aleph::FunctionalMixin< Derived, Type >::self().

Referenced by TEST(), TEST(), and TEST().

◆ first()

template<typename Derived , typename Type >
const Type * Aleph::FunctionalMixin< Derived, Type >::first ( ) const
inline

Get the first element.

Returns
Pointer to first element, or nullptr if empty.
Complexity
O(1).
Example
DynList<int> list = {1, 2, 3};
auto first_ptr = list.first(); // points to 1

Definition at line 1304 of file ah-dry-mixin.H.

References Aleph::FunctionalMixin< Derived, Type >::maps(), and Aleph::FunctionalMixin< Derived, Type >::self().

Referenced by Aleph::FunctionalMixin< Derived, Type >::first_or(), Aleph::FunctionalMixin< Derived, Type >::intersperse(), Aleph::FunctionalMixin< Derived, Type >::join_str(), TEST(), TEST(), TEST(), TEST(), and TEST().

◆ first_or()

template<typename Derived , typename Type >
Type Aleph::FunctionalMixin< Derived, Type >::first_or ( const Type default_val) const
inline

Get the first element or a default value.

Parameters
default_valValue to return if container is empty.
Returns
First element or default_val if empty.
Complexity
O(1).
Example
auto val = empty.first_or(-1); // -1

Definition at line 1329 of file ah-dry-mixin.H.

References Aleph::FunctionalMixin< Derived, Type >::first(), and Aleph::FunctionalMixin< Derived, Type >::maps().

Referenced by TEST(), and TEST().

◆ fold() [1/2]

template<typename Derived , typename Type >
template<class Operation >
Type Aleph::FunctionalMixin< Derived, Type >::fold ( const Type init,
Operation &&  operation = Operation() 
) const
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 773 of file ah-dry-mixin.H.

References Aleph::init, and Aleph::FunctionalMixin< Derived, Type >::maps().

◆ fold() [2/2]

template<typename Derived , typename Type >
template<class Operation >
Type Aleph::FunctionalMixin< Derived, Type >::fold ( const Type init,
Operation operation 
) const
inline

Simple fold with same type for accumulator and elements.

Simplified version of foldl() where accumulator has same type as elements.

Template Parameters
OperationBinary operation type.
Parameters
initInitial value.
operationBinary operation.
Returns
Final accumulated value.

Definition at line 761 of file ah-dry-mixin.H.

References Aleph::FunctionalMixin< Derived, Type >::for_each(), Aleph::init, and Aleph::FunctionalMixin< Derived, Type >::maps().

◆ fold_left()

template<typename Derived , typename Type >
template<typename __Type = Type>
__Type Aleph::FunctionalMixin< Derived, Type >::fold_left ( std::function< __Type(const __Type &, const Type &)>  operation,
const __Type init 
) const
inline

Left fold with operation first (alternative signature).

See also
foldl()

Definition at line 745 of file ah-dry-mixin.H.

References Aleph::init, and Aleph::FunctionalMixin< Derived, Type >::maps().

◆ foldl()

template<typename Derived , typename Type >
template<typename __Type = Type>
__Type Aleph::FunctionalMixin< Derived, Type >::foldl ( const __Type init,
std::function< __Type(const __Type &, const Type &)>  operation 
) const
inline

Left fold (reduce) with initial value.

Combines all elements using a binary operation, starting from an initial value. Computes: op(...op(op(init, x1), x2)..., xn).

Template Parameters
__TypeAccumulator type (default: same as element Type).
Parameters
initInitial value for the accumulator.
operationBinary operation: (accumulator, element) -> new_accumulator.
Returns
Final accumulated value.
Complexity
O(n).
Example
DynList<int> nums = {1, 2, 3, 4, 5};
// Sum all elements
int sum = nums.foldl<int>(0, [](int acc, int x) { return acc + x; });
// sum = 15
// Concatenate strings
DynList<std::string> words = {"hello", " ", "world"};
auto sentence = words.foldl<std::string>("", [](auto acc, auto s) {
return acc + s;
});
// sentence = "hello world"

Definition at line 730 of file ah-dry-mixin.H.

References Aleph::FunctionalMixin< Derived, Type >::for_each(), Aleph::init, and Aleph::FunctionalMixin< Derived, Type >::maps().

Referenced by TEST(), TEST(), and TEST().

◆ for_each() [1/4]

template<typename Derived , typename Type >
template<class Operation >
auto Aleph::FunctionalMixin< Derived, Type >::for_each ( Operation &&  operation = Operation()) -> decltype(self())
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 524 of file ah-dry-mixin.H.

References Aleph::FunctionalMixin< Derived, Type >::maps().

◆ for_each() [2/4]

template<typename Derived , typename Type >
template<class Operation >
auto Aleph::FunctionalMixin< Derived, Type >::for_each ( Operation &&  operation = Operation()) const -> decltype(self())
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 517 of file ah-dry-mixin.H.

References Aleph::FunctionalMixin< Derived, Type >::maps().

◆ for_each() [3/4]

template<typename Derived , typename Type >
template<class Operation >
auto Aleph::FunctionalMixin< Derived, Type >::for_each ( Operation operation) -> decltype(self())
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 505 of file ah-dry-mixin.H.

References Aleph::FunctionalMixin< Derived, Type >::maps(), and Aleph::FunctionalMixin< Derived, Type >::self().

◆ for_each() [4/4]

template<typename Derived , typename Type >
template<class Operation >
auto Aleph::FunctionalMixin< Derived, Type >::for_each ( Operation operation) const -> decltype(self())
inline

Apply an operation to each element (read-only).

Iterates through all elements, calling the operation on each. Unlike traverse(), always visits all elements (cannot stop early).

Template Parameters
OperationCallable with signature void(const Type&).
Parameters
operationThe operation to apply.
Returns
Reference to this container (for chaining).
Example
DynList<int> list = {1, 2, 3};
list.for_each([](int x) { std::cout << x << " "; });
// Output: 1 2 3
void for_each(Operation &operation)
Traverse all the container and performs an operation on each element.
Definition ah-dry.H:685

Definition at line 493 of file ah-dry-mixin.H.

References Aleph::FunctionalMixin< Derived, Type >::maps(), and Aleph::FunctionalMixin< Derived, Type >::self().

Referenced by Aleph::FunctionalMixin< Derived, Type >::chunk(), Aleph::FunctionalMixin< Derived, Type >::count_if(), Aleph::FunctionalMixin< Derived, Type >::enumerate(), Aleph::FunctionalMixin< Derived, Type >::filter(), Aleph::FunctionalMixin< Derived, Type >::fold(), Aleph::FunctionalMixin< Derived, Type >::foldl(), Aleph::FunctionalMixin< Derived, Type >::intersperse(), Aleph::FunctionalMixin< Derived, Type >::join_str(), Aleph::FunctionalMixin< Derived, Type >::last(), Aleph::FunctionalMixin< Derived, Type >::length(), Aleph::FunctionalMixin< Derived, Type >::maps(), Aleph::FunctionalMixin< Derived, Type >::max_by(), Aleph::FunctionalMixin< Derived, Type >::min_by(), Aleph::outer_product(), Aleph::FunctionalMixin< Derived, Type >::partition(), Aleph::FunctionalMixin< Derived, Type >::pfilter(), Aleph::FunctionalMixin< Derived, Type >::rev(), Aleph::FunctionalMixin< Derived, Type >::sliding(), TEST(), TEST(), Aleph::FunctionalMixin< Derived, Type >::to_dynlist(), Aleph::FunctionalMixin< Derived, Type >::to_vector(), Aleph::FunctionalMixin< Derived, Type >::tpartition(), and Aleph::FunctionalMixin< Derived, Type >::unique_by().

◆ forall() [1/2]

template<typename Derived , typename Type >
template<class Operation >
bool Aleph::FunctionalMixin< Derived, Type >::forall ( Operation &&  operation = Operation()) const
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 608 of file ah-dry-mixin.H.

References Aleph::FunctionalMixin< Derived, Type >::maps().

◆ forall() [2/2]

template<typename Derived , typename Type >
template<class Operation >
bool Aleph::FunctionalMixin< Derived, Type >::forall ( Operation operation) const
inline

Alias for all().

See also
all()

Definition at line 601 of file ah-dry-mixin.H.

References Aleph::FunctionalMixin< Derived, Type >::maps().

◆ has_value()

template<typename Derived , typename Type >
bool Aleph::FunctionalMixin< Derived, Type >::has_value ( const Type val) const
inline

Check if container has a value.

Parameters
valValue to search for.
Returns
true if val is found, false otherwise.
Requirements
Type must support operator==.
Complexity
O(n) worst case, O(1) best case (found early).
Note
Named has_value() to avoid conflicts with contains() in tree/hash containers which have O(log n) or O(1) implementations.
Example
DynList<int> list = {1, 2, 3};
list.has_value(2); // true
list.has_value(5); // false

Definition at line 1224 of file ah-dry-mixin.H.

Referenced by TEST(), TEST(), TEST(), TEST(), and TEST().

◆ index_of()

template<typename Derived , typename Type >
size_t Aleph::FunctionalMixin< Derived, Type >::index_of ( const Type val) const
inline

Find the index of a specific value.

Parameters
valValue to search for.
Returns
Index of val, or size_t(-1) if not found.
Requirements
Type must support operator==.
Complexity
O(n) worst case.
Example
DynList<int> list = {1, 2, 3, 4, 5};
auto idx = list.index_of(3); // 2
auto bad = list.index_of(99); // size_t(-1)

Definition at line 1461 of file ah-dry-mixin.H.

Referenced by TEST(), TEST(), and TEST().

◆ intersperse()

template<typename Derived , typename Type >
template<template< typename > class Container = Aleph::DynList>
Container< Type > Aleph::FunctionalMixin< Derived, Type >::intersperse ( const Type sep) const
inline

Intersperse a separator between elements.

Template Parameters
ContainerResult container type (default: DynList).
Parameters
sepSeparator to insert between each pair of elements.
Returns
New container with separator interspersed.
Complexity
O(n).
Example
DynList<int> list = {1, 2, 3};
auto i = list.intersperse(0); // {1, 0, 2, 0, 3}

Definition at line 1555 of file ah-dry-mixin.H.

References Aleph::FunctionalMixin< Derived, Type >::first(), Aleph::FunctionalMixin< Derived, Type >::for_each(), and Aleph::FunctionalMixin< Derived, Type >::maps().

Referenced by TEST(), TEST(), TEST(), and TEST().

◆ join()

template<typename Derived , typename Type >
template<typename StringType = std::string>
requires requires(Type a) { std::to_string(a); }
StringType Aleph::FunctionalMixin< Derived, Type >::join ( const StringType sep = StringType{", "}) const
inline

Join elements into a string with separator.

Parameters
sepSeparator string (default: ", ").
Returns
String with all elements joined.
Requirements
Type must be convertible to string via std::to_string or operator<<.
Complexity
O(n).
Example
DynList<int> list = {1, 2, 3};
auto s = list.join(", "); // "1, 2, 3"

Definition at line 1731 of file ah-dry-mixin.H.

Referenced by TEST(), TEST(), and TEST().

◆ join_str()

template<typename Derived , typename Type >
std::string Aleph::FunctionalMixin< Derived, Type >::join_str ( const std::string &  sep = ", ") const
inline

Join string elements with separator.

Parameters
sepSeparator string (default: ", ").
Returns
String with all elements joined.
Complexity
O(n).
Example
DynList<std::string> list = {"a", "b", "c"};
auto s = list.join_str("-"); // "a-b-c"

Definition at line 1760 of file ah-dry-mixin.H.

References Aleph::FunctionalMixin< Derived, Type >::first(), Aleph::FunctionalMixin< Derived, Type >::for_each(), and Aleph::FunctionalMixin< Derived, Type >::maps().

Referenced by TEST(), and TEST().

◆ last()

template<typename Derived , typename Type >
const Type * Aleph::FunctionalMixin< Derived, Type >::last ( ) const
inline

Get the last element.

Returns
Pointer to last element, or nullptr if empty.
Complexity
O(n) - must traverse all elements.
Example
DynList<int> list = {1, 2, 3};
auto last_ptr = list.last(); // points to 3

Definition at line 1348 of file ah-dry-mixin.H.

References Aleph::FunctionalMixin< Derived, Type >::for_each(), and Aleph::FunctionalMixin< Derived, Type >::maps().

Referenced by Aleph::Cnode::extract_word_from_stack(), Aleph::FunctionalMixin< Derived, Type >::last_or(), TEST(), TEST(), TEST(), TEST(), and TEST().

◆ last_or()

template<typename Derived , typename Type >
Type Aleph::FunctionalMixin< Derived, Type >::last_or ( const Type default_val) const
inline

Get the last element or a default value.

Parameters
default_valValue to return if container is empty.
Returns
Last element or default_val if empty.
Complexity
O(n).
Example
auto val = empty.last_or(-1); // -1

Definition at line 1372 of file ah-dry-mixin.H.

References Aleph::FunctionalMixin< Derived, Type >::last(), and Aleph::FunctionalMixin< Derived, Type >::maps().

Referenced by TEST(), and TEST().

◆ length()

template<typename Derived , typename Type >
size_t Aleph::FunctionalMixin< Derived, Type >::length ( ) const
inlinenoexcept

Count the number of elements.

Returns
Number of elements in the container.
Complexity
O(n) - must traverse all elements.
Note
If the container maintains a size counter, prefer using size() instead.

Definition at line 926 of file ah-dry-mixin.H.

References Aleph::count(), Aleph::FunctionalMixin< Derived, Type >::for_each(), and Aleph::FunctionalMixin< Derived, Type >::maps().

Referenced by TEST(), and TEST().

◆ maps() [1/2]

template<typename Derived , typename Type >
template<typename __Type = Type, template< typename > class Container = Aleph::DynList, class Operation = Dft_Map_Op<Type, __Type>>
Container< __Type > Aleph::FunctionalMixin< Derived, Type >::maps ( Operation &&  operation = Operation()) const
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 695 of file ah-dry-mixin.H.

References Aleph::FunctionalMixin< Derived, Type >::maps().

◆ maps() [2/2]

template<typename Derived , typename Type >
template<typename __Type = Type, template< typename > class Container = Aleph::DynList, class Operation = Dft_Map_Op<Type, __Type>>
Container< __Type > Aleph::FunctionalMixin< Derived, Type >::maps ( Operation &  operation) const
inline

Transform elements using a mapping function.

Creates a new container with each element transformed by the operation. This is the classic "map" operation from functional programming.

Template Parameters
__TypeResult type (default: same as input Type).
ContainerResult container type (default: DynList).
OperationCallable with signature __Type(const Type&).
Parameters
operationTransformation function.
Returns
New container with transformed elements.
Complexity
O(n).
Example
DynList<int> nums = {1, 2, 3};
// Square each number
auto squares = nums.maps<int>([](int x) { return x * x; });
// squares = {1, 4, 9}
// Convert to strings
auto strs = nums.maps<std::string>([](int x) { return std::to_string(x); });
// strs = {"1", "2", "3"}
Aleph::DynList< __T > maps(Operation &op) const
Map the elements of the container.
Definition ah-dry.H:904

Definition at line 681 of file ah-dry-mixin.H.

References Aleph::FunctionalMixin< Derived, Type >::for_each(), and Aleph::FunctionalMixin< Derived, Type >::maps().

Referenced by Aleph::FunctionalMixin< Derived, Type >::all(), Aleph::FunctionalMixin< Derived, Type >::all(), Aleph::FunctionalMixin< Derived, Type >::chunk(), Aleph::Cnode::clone(), Aleph::Cnode::clone(), Aleph::Cnode::contains(), Aleph::FunctionalMixin< Derived, Type >::count_if(), Aleph::FunctionalMixin< Derived, Type >::drop(), Aleph::FunctionalMixin< Derived, Type >::enumerate(), Aleph::FunctionalMixin< Derived, Type >::exists(), Aleph::FunctionalMixin< Derived, Type >::exists(), Aleph::Cnode::extract_word_from_stack(), Aleph::FunctionalMixin< Derived, Type >::filter(), Aleph::FunctionalMixin< Derived, Type >::filter(), Aleph::FunctionalMixin< Derived, Type >::find_index(), Aleph::FunctionalMixin< Derived, Type >::first(), Aleph::FunctionalMixin< Derived, Type >::first_or(), Aleph::FunctionalMixin< Derived, Type >::fold(), Aleph::FunctionalMixin< Derived, Type >::fold(), Aleph::FunctionalMixin< Derived, Type >::fold_left(), Aleph::FunctionalMixin< Derived, Type >::foldl(), Aleph::FunctionalMixin< Derived, Type >::for_each(), Aleph::FunctionalMixin< Derived, Type >::for_each(), Aleph::FunctionalMixin< Derived, Type >::for_each(), Aleph::FunctionalMixin< Derived, Type >::for_each(), Aleph::FunctionalMixin< Derived, Type >::forall(), Aleph::FunctionalMixin< Derived, Type >::forall(), Aleph::Cnode::insert_child(), Aleph::Cnode::insert_word(), Aleph::FunctionalMixin< Derived, Type >::intersperse(), Aleph::FunctionalMixin< Derived, Type >::join_str(), Aleph::FunctionalMixin< Derived, Type >::last(), Aleph::FunctionalMixin< Derived, Type >::last_or(), Aleph::FunctionalMixin< Derived, Type >::length(), Aleph::FunctionalMixin< Derived, Type >::maps(), Aleph::FunctionalMixin< Derived, Type >::maps(), Aleph::Cnode::mark_end_word(), Aleph::FunctionalMixin< Derived, Type >::max_by(), Aleph::FunctionalMixin< Derived, Type >::min_by(), Aleph::FunctionalMixin< Derived, Type >::mutable_for_each(), Aleph::FunctionalMixin< Derived, Type >::mutable_for_each(), Aleph::FunctionalMixin< Derived, Type >::none(), Aleph::FunctionalMixin< Derived, Type >::none(), Aleph::FunctionalMixin< Derived, Type >::partition(), Aleph::FunctionalMixin< Derived, Type >::partition(), Aleph::FunctionalMixin< Derived, Type >::pfilter(), Aleph::FunctionalMixin< Derived, Type >::pfilter(), Aleph::Cnode::print_words(), Aleph::FunctionalMixin< Derived, Type >::rev(), Aleph::Cnode::search_prefix(), Aleph::Cnode::search_word(), Aleph::FunctionalMixin< Derived, Type >::self(), Aleph::FunctionalMixin< Derived, Type >::self(), Aleph::FunctionalMixin< Derived, Type >::sliding(), Aleph::FunctionalMixin< Derived, Type >::take(), TEST(), TEST(), TEST(), Aleph::FunctionalMixin< Derived, Type >::to_dynlist(), Aleph::Cnode::to_str(), Aleph::FunctionalMixin< Derived, Type >::to_vector(), Aleph::FunctionalMixin< Derived, Type >::tpartition(), Aleph::FunctionalMixin< Derived, Type >::tpartition(), Aleph::FunctionalMixin< Derived, Type >::unique_by(), Aleph::Cnode::words(), Aleph::Cnode::words_with_prefix(), and Aleph::FunctionalMixin< Derived, Type >::zip_with().

◆ max()

template<typename Derived , typename Type >
const Type * Aleph::FunctionalMixin< Derived, Type >::max ( ) const
inline

Find the maximum element.

Returns
Pointer to maximum element, or nullptr if empty.
Requirements
Type must support operator<.
Complexity
O(n).
Example
DynList<int> list = {3, 1, 4, 1, 5};
auto max_ptr = list.max(); // points to 5
const Container::Item_Type * max_ptr(const Container &container, Cmp cmp=Cmp())
Find the maximum element in a container.

Definition at line 1129 of file ah-dry-mixin.H.

Referenced by TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), and TEST().

◆ max_by()

template<typename Derived , typename Type >
template<class Compare >
const Type * Aleph::FunctionalMixin< Derived, Type >::max_by ( Compare  cmp) const
inline

Find the maximum element using a custom comparator.

Template Parameters
CompareComparator type.
Parameters
cmpComparator function (returns true if first < second).
Returns
Pointer to maximum element, or nullptr if empty.
Complexity
O(n).
Example
DynList<std::string> list = {"apple", "pie", "a"};
auto longest = list.max_by([](auto& a, auto& b) {
return a.length() < b.length();
}); // points to "apple"

Definition at line 1188 of file ah-dry-mixin.H.

References cmp(), Aleph::FunctionalMixin< Derived, Type >::for_each(), and Aleph::FunctionalMixin< Derived, Type >::maps().

Referenced by TEST().

◆ min()

template<typename Derived , typename Type >
const Type * Aleph::FunctionalMixin< Derived, Type >::min ( ) const
inline

Find the minimum element.

Returns
Pointer to minimum element, or nullptr if empty.
Requirements
Type must support operator<.
Complexity
O(n).
Example
DynList<int> list = {3, 1, 4, 1, 5};
auto min_ptr = list.min(); // points to 1
const Container::Item_Type * min_ptr(const Container &container, Cmp cmp=Cmp())
Find the minimum element in a container.

Definition at line 1101 of file ah-dry-mixin.H.

Referenced by TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), and TEST().

◆ min_by()

template<typename Derived , typename Type >
template<class Compare >
const Type * Aleph::FunctionalMixin< Derived, Type >::min_by ( Compare  cmp) const
inline

Find the minimum element using a custom comparator.

Template Parameters
CompareComparator type.
Parameters
cmpComparator function (returns true if first < second).
Returns
Pointer to minimum element, or nullptr if empty.
Complexity
O(n).
Example
DynList<std::string> list = {"apple", "pie", "a"};
auto shortest = list.min_by([](auto& a, auto& b) {
return a.length() < b.length();
}); // points to "a"

Definition at line 1159 of file ah-dry-mixin.H.

References cmp(), Aleph::FunctionalMixin< Derived, Type >::for_each(), and Aleph::FunctionalMixin< Derived, Type >::maps().

Referenced by TEST().

◆ mutable_for_each() [1/2]

template<typename Derived , typename Type >
template<class Operation >
auto Aleph::FunctionalMixin< Derived, Type >::mutable_for_each ( Operation &&  operation = Operation()) -> decltype(self())
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 557 of file ah-dry-mixin.H.

References Aleph::FunctionalMixin< Derived, Type >::maps().

◆ mutable_for_each() [2/2]

template<typename Derived , typename Type >
template<class Operation >
auto Aleph::FunctionalMixin< Derived, Type >::mutable_for_each ( Operation operation) -> decltype(self())
inline

Apply an operation to each element (mutable).

Like for_each() but allows modifying elements.

Template Parameters
OperationCallable with signature void(Type&).
Parameters
operationThe operation to apply (can modify elements).
Returns
Reference to this container.
Example
DynList<int> list = {1, 2, 3};
list.mutable_for_each([](int& x) { x *= 2; });
// list = {2, 4, 6}
void mutable_for_each(Operation &operation)
Definition ah-dry.H:787

Definition at line 545 of file ah-dry-mixin.H.

References Aleph::FunctionalMixin< Derived, Type >::maps(), and Aleph::FunctionalMixin< Derived, Type >::self().

Referenced by TEST().

◆ none() [1/2]

template<typename Derived , typename Type >
template<class Predicate >
bool Aleph::FunctionalMixin< Derived, Type >::none ( Predicate &&  pred) const
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 1255 of file ah-dry-mixin.H.

References Aleph::FunctionalMixin< Derived, Type >::exists(), Aleph::FunctionalMixin< Derived, Type >::maps(), and pred.

◆ none() [2/2]

template<typename Derived , typename Type >
template<class Predicate >
bool Aleph::FunctionalMixin< Derived, Type >::none ( Predicate pred) const
inline

Check if no element satisfies a predicate.

Template Parameters
PredicatePredicate type.
Parameters
predPredicate function.
Returns
true if no element satisfies pred, false otherwise.
Complexity
O(n).
Note
This is the logical complement of exists().
Example
DynList<int> list = {2, 4, 6};
list.none([](int x) { return x % 2 != 0; }); // true (all even)

Definition at line 1248 of file ah-dry-mixin.H.

References Aleph::FunctionalMixin< Derived, Type >::exists(), Aleph::FunctionalMixin< Derived, Type >::maps(), and pred.

Referenced by TEST(), TEST(), and TEST().

◆ partition() [1/2]

template<typename Derived , typename Type >
template<class Operation >
std::pair< DynList< Type >, DynList< Type > > Aleph::FunctionalMixin< Derived, Type >::partition ( Operation &&  op = Operation()) const
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 884 of file ah-dry-mixin.H.

References Aleph::FunctionalMixin< Derived, Type >::maps().

◆ partition() [2/2]

template<typename Derived , typename Type >
template<class Operation >
std::pair< DynList< Type >, DynList< Type > > Aleph::FunctionalMixin< Derived, Type >::partition ( Operation op) const
inline

Partition elements by a predicate.

Splits the container into two lists: elements satisfying the predicate go into first, others go into second.

Template Parameters
OperationCallable with signature bool(const Type&).
Parameters
opPredicate function.
Returns
Pair of (matching_elements, non_matching_elements).
Example
DynList<int> nums = {1, 2, 3, 4, 5, 6};
auto [evens, odds] = nums.partition([](int x) { return x % 2 == 0; });
// evens = {2, 4, 6}, odds = {1, 3, 5}
std::pair< Aleph::DynList< T >, Aleph::DynList< T > > partition(Operation &op) const
Exclusive partition of container according to a filter criteria.
Definition ah-dry.H:1266

Definition at line 869 of file ah-dry-mixin.H.

References Aleph::FunctionalMixin< Derived, Type >::for_each(), and Aleph::FunctionalMixin< Derived, Type >::maps().

Referenced by TEST().

◆ pfilter() [1/2]

template<typename Derived , typename Type >
template<class Operation >
DynList< std::tuple< Type, size_t > > Aleph::FunctionalMixin< Derived, Type >::pfilter ( Operation &&  operation = Operation()) const
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 847 of file ah-dry-mixin.H.

References Aleph::FunctionalMixin< Derived, Type >::maps().

◆ pfilter() [2/2]

template<typename Derived , typename Type >
template<class Operation >
DynList< std::tuple< Type, size_t > > Aleph::FunctionalMixin< Derived, Type >::pfilter ( Operation operation) const
inline

Filter with position information.

Like filter(), but returns tuples of (element, index) for matching elements.

Template Parameters
OperationCallable with signature bool(const Type&).
Parameters
operationPredicate function.
Returns
DynList of tuples (element, original_index).
Example
DynList<int> nums = {1, 2, 3, 4, 5};
auto result = nums.pfilter([](int x) { return x > 2; });
// result = {(3, 2), (4, 3), (5, 4)}
Aleph::DynList< std::tuple< T, size_t > > pfilter(Operation &operation) const
Filter the elements of a container according to a matching criteria and determine its positions respe...
Definition ah-dry.H:1223

Definition at line 832 of file ah-dry-mixin.H.

References Aleph::FunctionalMixin< Derived, Type >::for_each(), and Aleph::FunctionalMixin< Derived, Type >::maps().

◆ product()

template<typename Derived , typename Type >
Type Aleph::FunctionalMixin< Derived, Type >::product ( const Type init) const
inline

Compute the product of all elements.

Parameters
initInitial value (default: Type{1} for numeric types).
Returns
Product of all elements starting from init.
Requirements
Type must support operator*.
Complexity
O(n).
Example
DynList<int> list = {1, 2, 3, 4};
auto prod = list.product(1); // 24

Definition at line 1074 of file ah-dry-mixin.H.

Referenced by TEST(), and TEST().

◆ rev()

template<typename Derived , typename Type >
template<template< typename > class Container = Aleph::DynList>
Container< Type > Aleph::FunctionalMixin< Derived, Type >::rev ( ) const
inline

Create a reversed copy.

Template Parameters
ContainerResult container type (default: DynList).
Returns
New container with elements in reverse order.
Complexity
O(n).
Example
DynList<int> list = {1, 2, 3};
auto reversed = list.rev();
// reversed = {3, 2, 1}
DynList & rev() noexcept
Definition htlist.H:1769

Definition at line 949 of file ah-dry-mixin.H.

References Aleph::FunctionalMixin< Derived, Type >::for_each(), and Aleph::FunctionalMixin< Derived, Type >::maps().

Referenced by TEST().

◆ self() [1/2]

◆ self() [2/2]

template<typename Derived , typename Type >
Derived & Aleph::FunctionalMixin< Derived, Type >::self ( )
inlineprotectednoexcept

Definition at line 465 of file ah-dry-mixin.H.

References Aleph::FunctionalMixin< Derived, Type >::maps().

◆ sliding()

template<typename Derived , typename Type >
template<template< typename > class Container = Aleph::DynList>
Container< Container< Type > > Aleph::FunctionalMixin< Derived, Type >::sliding ( size_t  size,
size_t  step = 1 
) const
inline

Create sliding windows of fixed size.

Template Parameters
ContainerResult container type (default: DynList).
Parameters
sizeWindow size.
stepStep between windows (default: 1).
Returns
Container of windows.
Complexity
O(n * size).
Example
DynList<int> list = {1, 2, 3, 4, 5};
auto windows = list.sliding(3); // {{1,2,3}, {2,3,4}, {3,4,5}}
auto windows2 = list.sliding(2, 2); // {{1,2}, {3,4}}

Definition at line 1632 of file ah-dry-mixin.H.

References Aleph::FunctionalMixin< Derived, Type >::all(), Aleph::FunctionalMixin< Derived, Type >::for_each(), Aleph::FunctionalMixin< Derived, Type >::maps(), and Aleph::size().

Referenced by TEST(), TEST(), TEST(), TEST(), and TEST().

◆ sum()

template<typename Derived , typename Type >
Type Aleph::FunctionalMixin< Derived, Type >::sum ( const Type init = Type{}) const
inline

Compute the sum of all elements.

Parameters
initInitial value (default: Type{}).
Returns
Sum of all elements starting from init.
Requirements
Type must support operator+.
Complexity
O(n).
Example
DynList<int> list = {1, 2, 3, 4, 5};
auto total = list.sum(); // 15
auto offset = list.sum(10); // 25
const long double offset[]
Offset values indexed by symbol string length (bounded by MAX_OFFSET_INDEX)

Definition at line 1046 of file ah-dry-mixin.H.

Referenced by TEST(), TEST(), TEST(), TEST(), and TEST().

◆ take()

template<typename Derived , typename Type >
template<template< typename > class Container = Aleph::DynList>
Container< Type > Aleph::FunctionalMixin< Derived, Type >::take ( const size_t  n) const
inline

Take the first n elements.

Template Parameters
ContainerResult container type (default: DynList).
Parameters
nMaximum number of elements to take.
Returns
New container with at most n elements from the beginning.
Complexity
O(min(n, size())).
Example
DynList<int> list = {1, 2, 3, 4, 5};
auto first3 = list.take(3); // {1, 2, 3}
auto all = list.take(100); // {1, 2, 3, 4, 5}
bool all(Operation &operation) const
Test if all elements satisfy a predicate.
Aleph::DynList< T > take(const size_t n) const
Return a list with the first n elements seen in the container during its traversal.
Definition ah-dry.H:1418

Definition at line 980 of file ah-dry-mixin.H.

References Aleph::FunctionalMixin< Derived, Type >::maps(), and Aleph::FunctionalMixin< Derived, Type >::self().

Referenced by TEST().

◆ to_dynlist()

template<typename Derived , typename Type >
template<typename DynListType = DynList<Type>>
DynListType Aleph::FunctionalMixin< Derived, Type >::to_dynlist ( ) const
inline

Convert container to DynList.

Creates a DynList containing all elements in traversal order.

Template Parameters
DynListTypeDynList type (default: DynList<Type>).
Returns
DynList containing all elements.
Complexity
O(n).
Example
BitArray bits = {1, 0, 1, 1};
Contiguous array of bits.
Definition bitArray.H:189
DynListType to_dynlist() const
Convert container to DynList.
Note
Requires DynList to be available (include htlist.H or tpl_dynList.H).

Definition at line 1706 of file ah-dry-mixin.H.

References Aleph::FunctionalMixin< Derived, Type >::for_each(), and Aleph::FunctionalMixin< Derived, Type >::maps().

Referenced by TEST(), TEST(), and TEST().

◆ to_vector()

template<typename Derived , typename Type >
std::vector< Type > Aleph::FunctionalMixin< Derived, Type >::to_vector ( ) const
inline

Convert to std::vector.

Returns
std::vector containing all elements.
Complexity
O(n).
Example
DynList<int> list = {1, 2, 3};
std::vector<int> vec = list.to_vector();
std::vector< T > to_vector() const
Convert container to std::vector.
Definition ah-dry.H:977

Definition at line 1678 of file ah-dry-mixin.H.

References Aleph::FunctionalMixin< Derived, Type >::for_each(), Aleph::FunctionalMixin< Derived, Type >::maps(), and Aleph::FunctionalMixin< Derived, Type >::self().

Referenced by TEST(), TEST(), and TEST().

◆ tpartition() [1/2]

template<typename Derived , typename Type >
template<class Operation >
std::tuple< DynList< Type >, DynList< Type > > Aleph::FunctionalMixin< Derived, Type >::tpartition ( Operation &&  op = Operation()) const
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 908 of file ah-dry-mixin.H.

References Aleph::FunctionalMixin< Derived, Type >::maps().

◆ tpartition() [2/2]

template<typename Derived , typename Type >
template<class Operation >
std::tuple< DynList< Type >, DynList< Type > > Aleph::FunctionalMixin< Derived, Type >::tpartition ( Operation op) const
inline

Partition returning tuple instead of pair.

See also
partition()

Definition at line 893 of file ah-dry-mixin.H.

References Aleph::DynList< T >::append(), Aleph::FunctionalMixin< Derived, Type >::for_each(), and Aleph::FunctionalMixin< Derived, Type >::maps().

◆ unique()

template<typename Derived , typename Type >
template<template< typename > class Container = Aleph::DynList>
requires requires(Type a, Type b) { { a == b } -> std::convertible_to<bool>; }
Container< Type > Aleph::FunctionalMixin< Derived, Type >::unique ( ) const
inline

Remove consecutive duplicate elements.

Template Parameters
ContainerResult container type (default: DynList).
Returns
New container with consecutive duplicates removed.
Requirements
Type must support operator==.
Complexity
O(n).
Example
DynList<int> list = {1, 1, 2, 2, 2, 3, 1, 1};
auto u = list.unique(); // {1, 2, 3, 1}

Definition at line 1489 of file ah-dry-mixin.H.

Referenced by TEST(), TEST(), TEST(), TEST(), and TEST().

◆ unique_by()

template<typename Derived , typename Type >
template<template< typename > class Container = Aleph::DynList, class EqPred >
Container< Type > Aleph::FunctionalMixin< Derived, Type >::unique_by ( EqPred  eq) const
inline

Remove consecutive duplicates using a custom equality predicate.

Template Parameters
ContainerResult container type (default: DynList).
EqPredEquality predicate type.
Parameters
eqPredicate that returns true if two elements are equal.
Returns
New container with consecutive duplicates removed.
Complexity
O(n).
Example
DynList<std::string> list = {"a", "A", "b", "B"};
auto u = list.unique_by([](auto& a, auto& b) {
return tolower(a[0]) == tolower(b[0]);
}); // {"a", "b"}
std::string tolower(const char *str)
Convert a C std::string to lower-case.

Definition at line 1524 of file ah-dry-mixin.H.

References Aleph::eq(), Aleph::FunctionalMixin< Derived, Type >::for_each(), and Aleph::FunctionalMixin< Derived, Type >::maps().

Referenced by TEST().

◆ zip_with()

template<typename Derived , typename Type >
template<class Other , template< typename > class Container = Aleph::DynList>
Container< std::pair< Type, typename Other::Item_Type > > Aleph::FunctionalMixin< Derived, Type >::zip_with ( const Other other) const
inline

Zip with another container.

Template Parameters
OtherThe other container type.
ContainerResult container type (default: DynList).
Parameters
otherThe container to zip with.
Returns
Container of pairs (element from this, element from other).
Note
Stops at the shorter container.
Complexity
O(min(n, m)).
Example
DynList<int> a = {1, 2, 3};
DynList<char> b = {'a', 'b', 'c'};
auto zipped = a.zip_with(b); // {(1,'a'), (2,'b'), (3,'c')}

Definition at line 1800 of file ah-dry-mixin.H.

References Aleph::FunctionalMixin< Derived, Type >::maps(), and Aleph::FunctionalMixin< Derived, Type >::self().

Referenced by TEST(), TEST(), TEST(), and TEST().


The documentation for this class was generated from the following file: