Aleph-w 7.10.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 >
requires CallableWith<Operation &, const Type &>
auto for_each (Operation &operation) const -> decltype(self())
 Apply an operation to each element (read-only).
 
template<class Operation >
requires CallableWith<Operation &, const Type &>
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 >
requires CallableWith<Operation &, const Type &>
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 >
requires CallableWith<Operation &, const Type &>
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 >
requires CallableWith<Operation &, Type &>
auto mutable_for_each (Operation &operation) -> decltype(self())
 Apply an operation to each element (mutable).
 
template<class Operation >
requires CallableWith<Operation &, Type &>
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 >
requires requires(const typename concepts_detail::defer<Derived, Operation>::type &c, Operation &op) { { c.template traverse<Operation>(op) } -> std::convertible_to<bool>; }
bool all (Operation &operation) const
 Test if all elements satisfy a predicate.
 
template<class Operation >
requires requires(const typename concepts_detail::defer<Derived, Operation>::type &c, Operation &op) { { c.template traverse<Operation>(op) } -> std::convertible_to<bool>; }
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 >
requires requires(const typename concepts_detail::defer<Derived, Operation>::type &c, Operation &op) { { c.template traverse<Operation>(op) } -> std::convertible_to<bool>; }
bool forall (Operation &operation) const
 Alias for all().
 
template<class Operation >
requires requires(const typename concepts_detail::defer<Derived, Operation>::type &c, Operation &op) { { c.template traverse<Operation>(op) } -> std::convertible_to<bool>; }
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 >
requires PredicateWith<Operation &, const Type &>
bool exists (Operation &operation) const
 Test if any element satisfies a predicate.
 
template<class Operation >
requires PredicateWith<Operation &, const Type &>
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.
 
Container< concepts_detail::map_result_t< R, Operation &, Type > > maps (Operation &operation) const
 
Container< concepts_detail::map_result_t< R, Operation &, Type > > maps (Operation &&operation=Operation()) const
 
template<typename Acc = Type>
Acc foldl (const Acc &init, std::function< Acc(const Acc &, const Type &)> operation) const
 Left fold (reduce) with initial value.
 
template<typename Acc = Type>
Acc fold_left (std::function< Acc(const Acc &, const Type &)> operation, const Acc &init) const
 Left fold with operation first (alternative signature).
 
template<class Operation >
requires requires(Type &acc, Operation &op, const Type &item) { acc = op(acc, item); }
Type fold (const Type &init, Operation &operation) const
 Simple fold with same type for accumulator and elements.
 
template<class Operation >
requires requires(Type &acc, Operation &op, const Type &item) { acc = op(acc, item); }
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 >
requires PredicateWith<Operation &, const Type &>
DynList< Type > filter (Operation &operation) const
 Filter elements by a predicate.
 
template<class Operation >
requires PredicateWith<Operation &, const Type &>
DynList< Type > filter (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 >
requires PredicateWith<Operation &, const Type &>
DynList< std::tuple< Type, size_t > > pfilter (Operation &operation) const
 Filter with position information.
 
template<class Operation >
requires PredicateWith<Operation &, const Type &>
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 >
requires PredicateWith<Operation &, const Type &>
std::pair< DynList< Type >, DynList< Type > > partition (Operation &op) const
 Partition elements by a predicate.
 
template<class Operation >
requires PredicateWith<Operation &, const Type &>
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 >
requires PredicateWith<Operation &, const Type &>
std::tuple< DynList< Type >, DynList< Type > > tpartition (Operation &op) const
 Partition returning tuple instead of pair.
 
template<class Operation >
requires PredicateWith<Operation &, const Type &>
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< Type > rev () const
 Create a reversed copy.
 
template<template< typename > class Container = Aleph::DynList>
Container< Type > take (const size_t n) const
 Take the first n elements.
 
template<template< typename > class Container = Aleph::DynList>
Container< Type > drop (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 Type * min () const
 Find the minimum element.
 
const Type * max () const
 Find the maximum element.
 
template<class Compare >
requires PredicateWith<Compare &, const Type &, const Type &>
const Type * min_by (Compare cmp) const
 Find the minimum element using a custom comparator.
 
template<class Compare >
requires PredicateWith<Compare &, const Type &, const Type &>
const Type * max_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 >
requires PredicateWith<Predicate &, const Type &>
bool none (Predicate &pred) const
 Check if no element satisfies a predicate.
 
template<class Predicate >
requires PredicateWith<Predicate &, const Type &>
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 >
requires PredicateWith<Predicate &, const Type &>
size_t count_if (Predicate pred) const
 Count elements satisfying a predicate.
 
const Type * first () const
 Get the first element.
 
Type first_or (const Type &default_val) const
 Get the first element or a default value.
 
const Type * last () 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 >
requires PredicateWith<Predicate &, const Type &>
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< Type > unique () const
 Remove consecutive duplicate elements.
 
template<template< typename > class Container = Aleph::DynList, class EqPred >
requires PredicateWith<EqPred &, const Type &, const Type &>
Container< Type > unique_by (EqPred eq) const
 Remove consecutive duplicates using a custom equality predicate.
 
template<template< typename > class Container = Aleph::DynList>
Container< Type > intersperse (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< Type > to_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.
 

Public Attributes

template<typename R = void, template< typename > class Container = Aleph::DynList, class Operation >
requires (Container<concepts_detail::map_result_t<R, Operation &, Type>> &l, Operation &op, const Type &item)
 and { l.append(std::invoke(op, item))
 Transform elements using a mapping function.
 

Protected Member Functions

const Derived & self () const noexcept
 
Derived & self () 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 503 of file ah-dry-mixin.H.

Member Function Documentation

◆ all() [1/2]

template<typename Derived , typename Type >
template<class Operation >
requires requires(const typename concepts_detail::defer<Derived, Operation>::type &c, Operation &op) { { c.template traverse<Operation>(op) } -> std::convertible_to<bool>; }
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 651 of file ah-dry-mixin.H.

◆ all() [2/2]

template<typename Derived , typename Type >
template<class Operation >
requires requires(const typename concepts_detail::defer<Derived, Operation>::type &c, Operation &op) { { c.template traverse<Operation>(op) } -> std::convertible_to<bool>; }
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
Doubly-linked list (defined in tpl_dynList.H).
Definition htlist.H:1231
bool all(Operation &operation) const
Check if all the elements of the container satisfy a condition.
Definition ah-dry.H:1666

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

References 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 1715 of file ah-dry-mixin.H.

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

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

◆ count_if()

template<typename Derived , typename Type >
template<class Predicate >
requires PredicateWith<Predicate &, const Type &>
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
size_t count_if(Operation &op) const
Count the elements that satisfy a criterion.
Definition ah-dry.H:1772

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

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

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:2757

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

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

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 1518 of file ah-dry-mixin.H.

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

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

◆ exists() [1/2]

template<typename Derived , typename Type >
template<class Operation >
requires PredicateWith<Operation &, const Type &>
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 711 of file ah-dry-mixin.H.

◆ exists() [2/2]

template<typename Derived , typename Type >
template<class Operation >
requires PredicateWith<Operation &, const Type &>
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 criterion.
Definition ah-dry.H:1707

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

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

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 >
requires PredicateWith<Operation &, const Type &>
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 903 of file ah-dry-mixin.H.

◆ filter() [2/2]

template<typename Derived , typename Type >
template<class Operation >
requires PredicateWith<Operation &, const Type &>
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 criterion.
Definition ah-dry.H:2356

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

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

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

◆ find_index()

template<typename Derived , typename Type >
template<class Predicate >
requires PredicateWith<Predicate &, const Type &>
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 the number of elements if none matches, as end() in the STL and as find_index() of the ah-dry.H containers.
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(const_search_is_noexcept< Operation >())
Find the position of an item in the container according to a searching criterion.
Definition ah-dry.H:921

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

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

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 1423 of file ah-dry-mixin.H.

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

Referenced by demo_linear_system(), demo_matrix_vector_mult(), demo_string_indexed_vector(), 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 1448 of file ah-dry-mixin.H.

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

Referenced by TEST(), and TEST().

◆ fold() [1/2]

template<typename Derived , typename Type >
template<class Operation >
requires requires(Type &acc, Operation &op, const Type &item) { acc = op(acc, item); }
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 863 of file ah-dry-mixin.H.

References Aleph::init.

◆ fold() [2/2]

template<typename Derived , typename Type >
template<class Operation >
requires requires(Type &acc, Operation &op, const Type &item) { acc = op(acc, item); }
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 850 of file ah-dry-mixin.H.

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

◆ fold_left()

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

Left fold with operation first (alternative signature).

See also
foldl()

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

References Aleph::init.

◆ foldl()

template<typename Derived , typename Type >
template<typename Acc = Type>
Acc Aleph::FunctionalMixin< Derived, Type >::foldl ( const Acc &  init,
std::function< Acc(const Acc &, 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
AccAccumulator 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"
Acc foldl(const Acc &init, Op &op) const
Fold the elements of the container to a specific result.
Definition ah-dry.H:2145

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

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

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

◆ for_each() [1/4]

template<typename Derived , typename Type >
template<class Operation >
requires CallableWith<Operation &, const Type &>
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 573 of file ah-dry-mixin.H.

◆ for_each() [2/4]

template<typename Derived , typename Type >
template<class Operation >
requires CallableWith<Operation &, const Type &>
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 565 of file ah-dry-mixin.H.

◆ for_each() [3/4]

template<typename Derived , typename Type >
template<class Operation >
requires CallableWith<Operation &, const Type &>
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 552 of file ah-dry-mixin.H.

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

◆ for_each() [4/4]

template<typename Derived , typename Type >
template<class Operation >
requires CallableWith<Operation &, const Type &>
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) const
Traverse all the container and performs an operation on each element.
Definition ah-dry.H:1475

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

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

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::Matrix< Trow, Tcol, NumType >::set_vector_as_col(), Aleph::Matrix< Trow, Tcol, NumType >::set_vector_as_row(), Aleph::FunctionalMixin< Derived, Type >::sliding(), Aleph::Gen_Polynomial< Coefficient >::sturm_sign_changes(), 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 >
requires requires(const typename concepts_detail::defer<Derived, Operation>::type &c, Operation &op) { { c.template traverse<Operation>(op) } -> std::convertible_to<bool>; }
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 675 of file ah-dry-mixin.H.

◆ forall() [2/2]

template<typename Derived , typename Type >
template<class Operation >
requires requires(const typename concepts_detail::defer<Derived, Operation>::type &c, Operation &op) { { c.template traverse<Operation>(op) } -> std::convertible_to<bool>; }
bool Aleph::FunctionalMixin< Derived, Type >::forall ( Operation &  operation) const
inline

Alias for all().

See also
all()

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

◆ 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 1335 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 the number of elements if it is 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); // 5, list.size()

Definition at line 1579 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 1681 of file ah-dry-mixin.H.

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

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 1869 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 1898 of file ah-dry-mixin.H.

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

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 1467 of file ah-dry-mixin.H.

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

Referenced by 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 1491 of file ah-dry-mixin.H.

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

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 1024 of file ah-dry-mixin.H.

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

Referenced by TEST(), and TEST().

◆ maps() [1/2]

template<typename Derived , typename Type >
Container< concepts_detail::map_result_t< R, Operation &, Type > > Aleph::FunctionalMixin< Derived, Type >::maps ( Operation &&  operation = Operation()) const
inline

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

◆ maps() [2/2]

template<typename Derived , typename Type >
Container< concepts_detail::map_result_t< R, Operation &, Type > > Aleph::FunctionalMixin< Derived, Type >::maps ( Operation &  operation) const
inline

◆ 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 1236 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 >
requires PredicateWith<Compare &, const Type &, const Type &>
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 1299 of file ah-dry-mixin.H.

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

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 1206 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 >
requires PredicateWith<Compare &, const Type &, const Type &>
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 1269 of file ah-dry-mixin.H.

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

Referenced by TEST().

◆ mutable_for_each() [1/2]

template<typename Derived , typename Type >
template<class Operation >
requires CallableWith<Operation &, Type &>
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 608 of file ah-dry-mixin.H.

◆ mutable_for_each() [2/2]

template<typename Derived , typename Type >
template<class Operation >
requires CallableWith<Operation &, Type &>
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}
and Aleph::dry_detail::MutablyTraversable< typename Aleph::concepts_detail::defer< Container, Operation >::type, T > void mutable_for_each(Operation &operation)
Apply a mutable operation to each element of the container.
Definition ah-dry.H:1633

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

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

Referenced by TEST().

◆ none() [1/2]

template<typename Derived , typename Type >
template<class Predicate >
requires PredicateWith<Predicate &, const Type &>
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 1373 of file ah-dry-mixin.H.

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

◆ none() [2/2]

template<typename Derived , typename Type >
template<class Predicate >
requires PredicateWith<Predicate &, const Type &>
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)
bool none(Operation &op) const
Test that no element satisfies a criterion.
Definition ah-dry.H:1746

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

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

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

◆ partition() [1/2]

template<typename Derived , typename Type >
template<class Operation >
requires PredicateWith<Operation &, const Type &>
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 980 of file ah-dry-mixin.H.

◆ partition() [2/2]

template<typename Derived , typename Type >
template<class Operation >
requires PredicateWith<Operation &, const Type &>
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 criterion.
Definition ah-dry.H:2515

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

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

Referenced by TEST().

◆ pfilter() [1/2]

template<typename Derived , typename Type >
template<class Operation >
requires PredicateWith<Operation &, const Type &>
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 941 of file ah-dry-mixin.H.

◆ pfilter() [2/2]

template<typename Derived , typename Type >
template<class Operation >
requires PredicateWith<Operation &, const Type &>
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 criterion and determine its positions resp...
Definition ah-dry.H:2463

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

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

◆ 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 1177 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:1734

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

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

Referenced by TEST().

◆ self() [1/2]

◆ self() [2/2]

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

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

◆ 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 1759 of file ah-dry-mixin.H.

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

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 1147 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:2696

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

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

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};
DynList<unsigned short> list = bits.to_dynlist();
Contiguous array of bits.
Definition bitArray.H:201
constexpr Bit_Column bits(const unsigned n)
Column of n bits without sign: the integers of [0, 2^n - 1].
Note
Requires DynList to be available (include htlist.H or tpl_dynList.H).

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

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

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:2088

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

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

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

◆ tpartition() [1/2]

template<typename Derived , typename Type >
template<class Operation >
requires PredicateWith<Operation &, const Type &>
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 1006 of file ah-dry-mixin.H.

◆ tpartition() [2/2]

template<typename Derived , typename Type >
template<class Operation >
requires PredicateWith<Operation &, const Type &>
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 990 of file ah-dry-mixin.H.

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

◆ 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 1612 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 >
requires PredicateWith<EqPred &, const Type &, const Type &>
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 1650 of file ah-dry-mixin.H.

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

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 1937 of file ah-dry-mixin.H.

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

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

Member Data Documentation

◆ and

template<typename Derived , typename Type >
template<typename R = void, template< typename > class Container = Aleph::DynList, class Operation >
requires (Container<concepts_detail::map_result_t<R, Operation &, Type>> &l, Operation &op, const Type &item)
Aleph::FunctionalMixin< Derived, Type >::and { l.append(std::invoke(op, item))

Transform elements using a mapping function.

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

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

Template Parameters
RItem type of the result, or void (the default) to take the type that operation returns, without references and const.
ContainerResult container type (default: DynList).
OperationCallable with signature R(const Type&), or a pointer to member; without operation, each item is converted to R, or copied if R is not given.
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 x) { return x * x; });
// squares = {1, 4, 9}, a DynList<int>
// Convert to strings: the item type is deduced
auto strs = nums.maps([](int x) { return std::to_string(x); });
// strs = {"1", "2", "3"}, a DynList<std::string>
// Force the item type
auto longs = nums.maps<long>([](int x) { return x; });
Aleph::DynList< Aleph::dry_detail::map_result_t< R, Operation &, T > > maps(Operation &op) const
Definition ah-dry.H:1829

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

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


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