From 7574e3836eec13e6f632b811e6bf001f2e3d2a1d Mon Sep 17 00:00:00 2001 From: Adrian Kummerlaender Date: Sun, 18 Jan 2015 13:58:36 +0100 Subject: Implemented higher order function `fold` * applies a given _function_ to each _Cons_ starting with a initial value * added appropriate test case --- src/list/operation/higher/fold.h | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 src/list/operation/higher/fold.h (limited to 'src') diff --git a/src/list/operation/higher/fold.h b/src/list/operation/higher/fold.h new file mode 100644 index 0000000..6ad4bd7 --- /dev/null +++ b/src/list/operation/higher/fold.h @@ -0,0 +1,28 @@ +#ifndef TYPEASVALUE_SRC_LIST_OPERATION_HIGHER_FOLD_H_ +#define TYPEASVALUE_SRC_LIST_OPERATION_HIGHER_FOLD_H_ + +namespace tav { + +template < + template class Function, + typename Initial, + typename Current +> +struct Fold { + typedef typename Function< + Head, + typename Fold>::type + >::type type; +}; + +template < + template class Function, + typename Initial +> +struct Fold { + typedef Initial type; +}; + +} + +#endif // TYPEASVALUE_SRC_LIST_OPERATION_HIGHER_FOLD_H_ -- cgit v1.2.3