aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/conditional/cond.h24
-rw-r--r--src/list/cons.h28
-rw-r--r--src/list/operation/higher/map.h34
3 files changed, 25 insertions, 61 deletions
diff --git a/src/conditional/cond.h b/src/conditional/cond.h
index f6b7965..eeb31b6 100644
--- a/src/conditional/cond.h
+++ b/src/conditional/cond.h
@@ -10,26 +10,18 @@ namespace tav {
namespace detail {
-template <typename... Branches>
-class Cond {
- private:
- template <typename Pair>
- using predicate = IsTrue<tav::Car<Pair>>;
-
- public:
- typedef tav::Cdr<
- tav::Find<
- predicate,
- tav::List<Branches...>
- >
- > type;
-
-};
+template <typename Pair>
+using cond_predicate = IsTrue<Car<Pair>>;
}
template <typename... Branches>
-using Cond = Eval<detail::Cond<Branches...>>;
+using Cond = Cdr<
+ Find<
+ detail::cond_predicate,
+ List<Branches...>
+ >
+>;
}
diff --git a/src/list/cons.h b/src/list/cons.h
index 95783b2..dbd4c0b 100644
--- a/src/list/cons.h
+++ b/src/list/cons.h
@@ -5,30 +5,6 @@
namespace tav {
-namespace detail {
-
-template <typename Pair>
-struct Car {
- static_assert(
- IsPair<Pair>::value,
- "Pair type required"
- );
-
- typedef typename Pair::car type;
-};
-
-template <typename Pair>
-struct Cdr {
- static_assert(
- IsPair<Pair>::value,
- "Pair type required"
- );
-
- typedef typename Pair::cdr type;
-};
-
-}
-
template <
typename CAR,
typename CDR
@@ -36,10 +12,10 @@ template <
using Cons = Pair<CAR, CDR>;
template <typename Pair>
-using Car = Eval<detail::Car<Pair>>;
+using Car = typename Pair::car;
template <typename Pair>
-using Cdr = Eval<detail::Cdr<Pair>>;
+using Cdr = typename Pair::cdr;
}
diff --git a/src/list/operation/higher/map.h b/src/list/operation/higher/map.h
index cc30355..00956a5 100644
--- a/src/list/operation/higher/map.h
+++ b/src/list/operation/higher/map.h
@@ -7,24 +7,16 @@ namespace tav {
namespace detail {
-template <
- template<typename> class Function,
- typename List
->
-class Map {
- private:
- template <
- typename Current,
- typename Previous
- >
- using function_wrapper = Cons<
- Eval<Function<Current>>,
- Previous
- >;
-
- public:
- using type = tav::Fold<function_wrapper, void, List>;
-
+template <template<typename> class Function>
+struct map_transformation {
+ template <
+ typename Current,
+ typename Previous
+ >
+ using function = Cons<
+ Eval<Function<Current>>,
+ Previous
+ >;
};
}
@@ -33,7 +25,11 @@ template <
template<typename> class Function,
typename List
>
-using Map = Eval<detail::Map<Function, List>>;
+using Map = Fold<
+ detail::map_transformation<Function>::template function,
+ void,
+ List
+>;
}