µEvLoop
A fast and lightweight event loop aimed at embedded platforms in C99.
Data Structures | Functions
functional.h File Reference

Contains helpers for composing and augumenting closures. More...

#include "uevloop/utils/closure.h"
#include "uevloop/utils/pipeline.h"
#include "uevloop/utils/conditional.h"
#include "uevloop/utils/iterator.h"
Include dependency graph for functional.h:

Go to the source code of this file.

Data Structures

struct  uel_func_mapper_t
 Maps elements of an iterator to an area of memory. Each element is assigned to a void pointer slot. More...
 

Functions

void uel_func_mapper_init (uel_func_mapper_t *mapper, uel_iterator_t *iterator, void **destination, size_t limit)
 Initialises a mapper object. More...
 
uel_closure_t uel_func_pipeline (uel_pipeline_t *pipeline)
 Wraps a pipeline in a closure. More...
 
uel_closure_t uel_func_conditional (uel_conditional_t *conditional)
 Wraps a conditional in a closure. More...
 
uel_closure_t uel_func_foreach (uel_closure_t *closure)
 Wraps a closure in a foreach construct. More...
 
uel_closure_t uel_func_map (uel_closure_t *closure)
 Wraps a closure in a map construct. More...
 
uel_closure_t uel_func_find (uel_closure_t *closure)
 Wraps a closure in a find construct. More...
 
uel_closure_t uel_func_count (uel_closure_t *closure)
 Wraps a closure in a count construct. More...
 
uel_closure_t uel_func_all (uel_closure_t *closure)
 Wraps a closure in a all construct. More...
 
uel_closure_t uel_func_none (uel_closure_t *closure)
 Wraps a closure in a none construct. More...
 
uel_closure_t uel_func_any (uel_closure_t *closure)
 Wraps a closure in a all construct. More...
 

Detailed Description

Contains helpers for composing and augumenting closures.

Function Documentation

◆ uel_func_all()

uel_closure_t uel_func_all ( uel_closure_t *  closure)

Wraps a closure in a all construct.

Creates a new closure based on a supplied closure. This new closure accepts an uel_iterator_t as parameter and applies the supplied closure to each element yielded by this iterator.

If all enumerate elements cause the supplied closure to return true, this new closure also returns true. Otherwise, it returns false.

Parameters
closureThe test to be applied against each enumerated element
Returns
Whether all elements pass the supplied test closure.

◆ uel_func_any()

uel_closure_t uel_func_any ( uel_closure_t *  closure)

Wraps a closure in a all construct.

Creates a new closure based on a supplied closure. This new closure accepts an uel_iterator_t as parameter and applies the supplied closure to each element yielded by this iterator.

If any enumerate elements cause the supplied closure to return true, this new closure also returns true. Otherwise, it returns false.

Parameters
closureThe test to be applied against each enumerated element
Returns
Whether any elements pass the supplied test closure.

◆ uel_func_conditional()

uel_closure_t uel_func_conditional ( uel_conditional_t *  conditional)

Wraps a conditional in a closure.

This function wraps a conditional in a closure. When invoked, the closure's parameters will be forwarded to the conditional. Also, the conditional's returned value will be returned from the closure.

Parameters
conditionalThe conditional to be wrapped
Returns
A closure that, when invoked, will apply the supplied conditional

◆ uel_func_count()

uel_closure_t uel_func_count ( uel_closure_t *  closure)

Wraps a closure in a count construct.

Creates a new closure based on a supplied closure. This new closure accepts an uel_iterator_t as parameter and applies the supplied closure to each element yielded by this iterator.

This new closure counts the number of enumerated elements that caused the test closure to return true.

Parameters
closureThe test to be applied against each enumerated element
Returns
The number of elements that passed the supplied test closure.

◆ uel_func_find()

uel_closure_t uel_func_find ( uel_closure_t *  closure)

Wraps a closure in a find construct.

Creates a new closure based on a supplied closure. This new closure accepts an uel_iterator_t as parameter and applies the supplied closure to each element yielded by this iterator.

When some enumerated element causes the supplied closure to return true, its address is returned by the new closure.

Parameters
closureThe test to be applied against each enumerated element
Returns
The address of the first element that passes the supplied test. If no such element is found, returns NULL.

◆ uel_func_foreach()

uel_closure_t uel_func_foreach ( uel_closure_t *  closure)

Wraps a closure in a foreach construct.

Creates a new closure based on a supplied closure. When invoked, this new closure takes an uel_iterator_t for parameter and yields each element in it to the supplied closure.

See uel_iterator_foreach().

Parameters
closureA reference to the closure to be wrapped

◆ uel_func_map()

uel_closure_t uel_func_map ( uel_closure_t *  closure)

Wraps a closure in a map construct.

Creates a new closure based on a supplied closure. This new closure takes an uel_func_mapper_t for parameter describing the mapping relation between elements yielded from an iterator and a region of memory.

When invoked, this new closure passes each element enumerated by this mapper as parameter to the supplied closure and stores its returned value sequentially in the destination area. It then returns the destination address.

See uel_iterator_map().

Parameters
closureA reference to the closure to be wrapped

◆ uel_func_mapper_init()

void uel_func_mapper_init ( uel_func_mapper_t *  mapper,
uel_iterator_t *  iterator,
void **  destination,
size_t  limit 
)

Initialises a mapper object.

Parameters
mapperThe mapper instance to be initialised
iteratorThe iterator responsible for enumerating elements
destinationAn array of void pointers to where elements will be mapped
limitThe maximum size of elements that can be mapped

◆ uel_func_none()

uel_closure_t uel_func_none ( uel_closure_t *  closure)

Wraps a closure in a none construct.

Creates a new closure based on a supplied closure. This new closure accepts an uel_iterator_t as parameter and applies the supplied closure to each element yielded by this iterator.

If all enumerate elements cause the supplied closure to return false, this new closure also returns true. Otherwise, it returns false.

Parameters
closureThe test to be applied against each enumerated element
Returns
Whether all elements are reproved in the supplied test closure.

◆ uel_func_pipeline()

uel_closure_t uel_func_pipeline ( uel_pipeline_t *  pipeline)

Wraps a pipeline in a closure.

This function wraps a pipeline in a closure. When invoked, the closure's parameters will be forwarded to the pipeline. Also, the pipeline's returned value will be returned from the closure.

Parameters
pipelineThe pipeline to be wrapped
Returns
A closure that, when invoked, will apply the supplied pipeline