AnCH Framework 0.2
Another C++ Hack: C++23 utility libraries
Loading...
Searching...
No Matches
anch::Fluent< T, C > Class Template Reference

Java style fuent class. More...

#include <fluent.hpp>

Collaboration diagram for anch::Fluent< T, C >:

Public Member Functions

 Fluent ()=delete
 Fluent (C< T > &container)
 Fluent (C< T > &&container)
 Fluent (const Fluent &other)=default
 Fluent (Fluent &&other) noexcept=default
 ~Fluent ()=default
Fluent & filter (std::function< bool(const T &)> predicate)
Fluent & skip (uint64_t skip)
Fluent & limit (uint64_t limit)
Fluent & concat (Fluent< T, C > &other) noexcept
bool allMatch (std::function< bool(const T &)> predicate)
bool anyMatch (std::function< bool(const T &)> predicate)
bool noneMatch (std::function< bool(const T &)> predicate)
void forEach (std::function< void(T &)> action)
template<typename U>
Fluent< U, std::vector > map (std::function< U(const T &)> mapper)
template<typename D>
void collect (D &container, std::function< void(D &, const T &)> collector)
template<typename D>
D collect (std::function< void(D &, const T &)> collector)
template<typename D, typename R>
void collect (D &container, R(D::*collector)(const T &))
template<typename D, typename R>
D collect (R(D::*collector)(const T &))

Detailed Description

template<typename T, template< typename > typename C>
class anch::Fluent< T, C >

Java style fuent class.

Fluent aims to lazily apply treatment on container.
Every operation is stored until final operation is call. They are applied in their insertion order.
skip and limit count elements across concatenated fluents (concat) ; only the operations of the first fluent are applied.
Final operations can be called several times: skip and limit counters are reset on each call.
A fluent built on a container reference does not own it: the container has to outlive the fluent. A fluent built on a temporary container (or returned by map) owns its values.

Author
Vincent Lachenal

Constructor & Destructor Documentation

◆ Fluent() [1/5]

template<typename T, template< typename > typename C>
anch::Fluent< T, C >::Fluent ( )
delete

Forbids Fluent constructor

◆ Fluent() [2/5]

template<typename T, template< typename > typename C>
anch::Fluent< T, C >::Fluent ( C< T > & container)

Build fluent from container. The container has to outlive the fluent.

Parameters
containerthe container

◆ Fluent() [3/5]

template<typename T, template< typename > typename C>
anch::Fluent< T, C >::Fluent ( C< T > && container)

Build fluent from temporary container. The fluent owns the values.

Parameters
containerthe container

◆ Fluent() [4/5]

template<typename T, template< typename > typename C>
anch::Fluent< T, C >::Fluent ( const Fluent< T, C > & other)
default

Fluent copy constructor (values are shared)

Here is the call graph for this function:

◆ Fluent() [5/5]

template<typename T, template< typename > typename C>
anch::Fluent< T, C >::Fluent ( Fluent< T, C > && other)
defaultnoexcept

Fluent move constructor

Here is the call graph for this function:

◆ ~Fluent()

template<typename T, template< typename > typename C>
anch::Fluent< T, C >::~Fluent ( )
default

Fluent destructor

Member Function Documentation

◆ allMatch()

template<typename T, template< typename > typename C>
bool anch::Fluent< T, C >::allMatch ( std::function< bool(const T &)> predicate)

Check if every items in fluent match a predicate

Parameters
predicatethe function to use to check items

◆ anyMatch()

template<typename T, template< typename > typename C>
bool anch::Fluent< T, C >::anyMatch ( std::function< bool(const T &)> predicate)

Check if there is at least one item in fluent that matches a predicate

Parameters
predicatethe function to use to check items

◆ collect() [1/4]

template<typename T, template< typename > typename C>
template<typename D, typename R>
void anch::Fluent< T, C >::collect ( D & container,
R(D::* collector )(const T &) )

Collect fluent items in container

Parameters
containerthe container to fill
collectorthe collector function

◆ collect() [2/4]

template<typename T, template< typename > typename C>
template<typename D>
void anch::Fluent< T, C >::collect ( D & container,
std::function< void(D &, const T &)> collector )

Collect fluent items in container

Parameters
containerthe container to fill
collectorthe collector function

◆ collect() [3/4]

template<typename T, template< typename > typename C>
template<typename D, typename R>
D anch::Fluent< T, C >::collect ( R(D::* collector )(const T &))

Collect fluent items in container

Parameters
collectorthe collector function
Returns
the result container

◆ collect() [4/4]

template<typename T, template< typename > typename C>
template<typename D>
D anch::Fluent< T, C >::collect ( std::function< void(D &, const T &)> collector)

Collect fluent items in container

Parameters
collectorthe collector function
Returns
the result container

◆ concat()

template<typename T, template< typename > typename C>
Fluent & anch::Fluent< T, C >::concat ( Fluent< T, C > & other)
noexcept

Fluent lazy 'concatenation'.
The concatenated fluent has to outlive this one.

Parameters
otherthe fluent to concatenate
Here is the call graph for this function:

◆ filter()

template<typename T, template< typename > typename C>
Fluent & anch::Fluent< T, C >::filter ( std::function< bool(const T &)> predicate)

Add filter function

Parameters
predicatethe filter function
Returns
the current Fluent
Here is the call graph for this function:

◆ forEach()

template<typename T, template< typename > typename C>
void anch::Fluent< T, C >::forEach ( std::function< void(T &)> action)

Apply treatment for each item in fluent.
Items are passed by reference: the action can modify them.

Parameters
actionthe function to execute on each item

◆ limit()

template<typename T, template< typename > typename C>
Fluent & anch::Fluent< T, C >::limit ( uint64_t limit)

Limit the number of elements

Parameters
limitthe number maximum of elements to treat
Returns
the current Fluent
Here is the call graph for this function:

◆ map()

template<typename T, template< typename > typename C>
template<typename U>
Fluent< U, std::vector > anch::Fluent< T, C >::map ( std::function< U(const T &)> mapper)

Create a new fluent transforming current fluent type into another.

Parameters
mapperthe mapping function
Here is the call graph for this function:

◆ noneMatch()

template<typename T, template< typename > typename C>
bool anch::Fluent< T, C >::noneMatch ( std::function< bool(const T &)> predicate)

Check if there is no item in fluent that matches a predicate

Parameters
predicatethe function to use to check items

◆ skip()

template<typename T, template< typename > typename C>
Fluent & anch::Fluent< T, C >::skip ( uint64_t skip)

Skip elements

Parameters
skipthe elements to skip
Returns
the current Fluent
Here is the call graph for this function:

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