diff options
author | Adrian Kummerlaender | 2015-01-18 13:58:36 +0100 |
---|---|---|
committer | Adrian Kummerlaender | 2015-01-18 13:58:36 +0100 |
commit | 7574e3836eec13e6f632b811e6bf001f2e3d2a1d (patch) | |
tree | 4ebdaf0cd82082678de8733a4f2724e2b3946dc9 /src/list | |
parent | 8943b2e30f8275619df0cf89f1e8ebc7deb58ca5 (diff) | |
download | TypeAsValue-7574e3836eec13e6f632b811e6bf001f2e3d2a1d.tar TypeAsValue-7574e3836eec13e6f632b811e6bf001f2e3d2a1d.tar.gz TypeAsValue-7574e3836eec13e6f632b811e6bf001f2e3d2a1d.tar.bz2 TypeAsValue-7574e3836eec13e6f632b811e6bf001f2e3d2a1d.tar.lz TypeAsValue-7574e3836eec13e6f632b811e6bf001f2e3d2a1d.tar.xz TypeAsValue-7574e3836eec13e6f632b811e6bf001f2e3d2a1d.tar.zst TypeAsValue-7574e3836eec13e6f632b811e6bf001f2e3d2a1d.zip |
Implemented higher order function `fold`
* applies a given _function_ to each _Cons_ starting with a initial value
* added appropriate test case
Diffstat (limited to 'src/list')
-rw-r--r-- | src/list/operation/higher/fold.h | 28 |
1 files changed, 28 insertions, 0 deletions
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<typename, typename> class Function, + typename Initial, + typename Current +> +struct Fold { + typedef typename Function< + Head<Current>, + typename Fold<Function, Initial, Tail<Current>>::type + >::type type; +}; + +template < + template<typename, typename> class Function, + typename Initial +> +struct Fold<Function, Initial, void> { + typedef Initial type; +}; + +} + +#endif // TYPEASVALUE_SRC_LIST_OPERATION_HIGHER_FOLD_H_ |