aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/list/operation/higher/drop_while.h29
-rw-r--r--src/list/operation/higher/take_while.h1
-rw-r--r--test.cc36
3 files changed, 65 insertions, 1 deletions
diff --git a/src/list/operation/higher/drop_while.h b/src/list/operation/higher/drop_while.h
new file mode 100644
index 0000000..a6ab8c4
--- /dev/null
+++ b/src/list/operation/higher/drop_while.h
@@ -0,0 +1,29 @@
+#ifndef TYPEASVALUE_SRC_LIST_OPERATION_HIGHER_DROP_WHILE_H_
+#define TYPEASVALUE_SRC_LIST_OPERATION_HIGHER_DROP_WHILE_H_
+
+#include "conditional/if.h"
+
+namespace tav {
+
+template <
+ template<typename> class Predicate,
+ typename Current
+>
+struct DropWhile {
+ typedef If<
+ Predicate<Head<Current>>::type::value,
+ typename DropWhile<Predicate, Tail<Current>>::type,
+ Current
+ > type;
+};
+
+template <
+ template<typename> class Predicate
+>
+struct DropWhile<Predicate, void> {
+ typedef void type;
+};
+
+}
+
+#endif // TYPEASVALUE_SRC_LIST_OPERATION_HIGHER_DROP_WHILE_H_
diff --git a/src/list/operation/higher/take_while.h b/src/list/operation/higher/take_while.h
index 01062f4..1ee6736 100644
--- a/src/list/operation/higher/take_while.h
+++ b/src/list/operation/higher/take_while.h
@@ -1,7 +1,6 @@
#ifndef TYPEASVALUE_SRC_LIST_OPERATION_HIGHER_TAKE_WHILE_H_
#define TYPEASVALUE_SRC_LIST_OPERATION_HIGHER_TAKE_WHILE_H_
-#include "type.h"
#include "conditional/if.h"
namespace tav {
diff --git a/test.cc b/test.cc
index 6accc0e..9351afd 100644
--- a/test.cc
+++ b/test.cc
@@ -13,6 +13,7 @@
#include "list/operation/higher/query.h"
#include "list/operation/higher/find.h"
#include "list/operation/higher/take_while.h"
+#include "list/operation/higher/drop_while.h"
#include "list/generator/iota.h"
#include "list/generator/make_list.h"
#include "list/generator/higher/list_tabulate.h"
@@ -754,6 +755,41 @@ static_assert(
"(take-while odd? (list 2 4 5 6)) != void"
);
+// list drop while
+
+static_assert(
+ std::is_same<
+ tav::List<tav::Int<5>, tav::Int<6>>::type,
+ tav::DropWhile<
+ tav::Even,
+ tav::List<tav::Int<2>, tav::Int<4>, tav::Int<5>, tav::Int<6>>::type
+ >::type
+ >::value,
+ "(drop-while even? (list 2 4 5 6)) != (list 5 6)"
+);
+
+static_assert(
+ std::is_same<
+ tav::List<tav::Int<2>, tav::Int<4>, tav::Int<6>>::type,
+ tav::DropWhile<
+ tav::Odd,
+ tav::List<tav::Int<2>, tav::Int<4>, tav::Int<6>>::type
+ >::type
+ >::value,
+ "(drop-while odd? (list 2 4 6)) != (list 2 4 6)"
+);
+
+static_assert(
+ std::is_same<
+ void,
+ tav::DropWhile<
+ tav::Even,
+ tav::List<tav::Int<2>, tav::Int<4>, tav::Int<6>>::type
+ >::type
+ >::value,
+ "(drop-while even? (list 2 4 6)) != void"
+);
+
// function apply
static_assert(