summaryrefslogtreecommitdiffstats
path: root/sca-cpp/trunk/kernel/list.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'sca-cpp/trunk/kernel/list.hpp')
-rw-r--r--sca-cpp/trunk/kernel/list.hpp11
1 files changed, 11 insertions, 0 deletions
diff --git a/sca-cpp/trunk/kernel/list.hpp b/sca-cpp/trunk/kernel/list.hpp
index 753b33b6a0..e20f3fbd8e 100644
--- a/sca-cpp/trunk/kernel/list.hpp
+++ b/sca-cpp/trunk/kernel/list.hpp
@@ -523,6 +523,17 @@ template<typename T> inline const T listRef(const list<T>& l, const size_t i) no
}
/**
+ * Returns a new list consisting of the first k elements of a list.
+ */
+template<typename T> inline const list<T> listHead(const list<T>& l, const size_t k) noexcept {
+ if(k == 0)
+ return list<T>();
+ if(isNull(l))
+ return l;
+ return cons<T>(car(l), listHead(cdr(l), k - 1));
+}
+
+/**
* Returns the tail of a list, ommiting the first k elements.
*/
template<typename T> inline const list<T> listTail(const list<T>& l, const size_t k) noexcept {