It's just for test purpose.
This is a collection of functional programming concepts implemented in C.
#include <functional.h>
#include <stdio.h>
int main(void) {
int array[] = {1, 2, 3, 4, 5};
float array[] = {4.0f, 2.0f, 4.0f};
float result = foldl(lambda(float, (float acc, float element) { return acc / element; }), array, 64.0f);
printf("result = %f\n", result);
return 0;
}
Output
result = 0.500000
Lambda is a function that can be passed as an argument to another function.
lambda(return_type, (argument_type argument_name, ...) { function_body; })
fmap is a function that applies a function to each element of an array.
fmap(function, array)
foldl is a function that applies a function to each element of an array and accumulates the result.
foldl(function, array, initial_value)
foldr is a function that applies a function to each element of an array and accumulates the result.
foldr(function, array, initial_value)