aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--list.cpp10
1 files changed, 10 insertions, 0 deletions
diff --git a/list.cpp b/list.cpp
index b83b018..caa4fbc 100644
--- a/list.cpp
+++ b/list.cpp
@@ -76,6 +76,16 @@ T reduce(List<T> *lst, T (*reducer) (T, T), T init = 0)
}
template <typename T>
+List<T> *filter(List<T> *lst, bool (*f)(T), List<T> *new_lst = nullptr)
+{
+ if (!lst)
+ return new_lst;
+ if (f(lst->value))
+ new_lst = append(new_lst, lst->value);
+ return filter(lst->next, f, new_lst);
+}
+
+template <typename T>
std::ostream& operator<<(std::ostream& ostream, const List<T> *lst)
{
if (!lst)