aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/functions.lisp2
-rw-r--r--tests/functions.lisp9
2 files changed, 10 insertions, 1 deletions
diff --git a/lib/functions.lisp b/lib/functions.lisp
index 40e940a..dd9976d 100644
--- a/lib/functions.lisp
+++ b/lib/functions.lisp
@@ -27,7 +27,7 @@ each member is STEP distance apart."
(loop :for i :from start :to (1- end) :by step
:collect i)))
-(fn take (n lst) (-> (fixnum list) list)
+(fn take (n lst) (-> (fixnum sequence) sequence)
"Return the first N elements of LST."
(subseq lst 0 n))
diff --git a/tests/functions.lisp b/tests/functions.lisp
index 0025827..8582213 100644
--- a/tests/functions.lisp
+++ b/tests/functions.lisp
@@ -39,3 +39,12 @@
(true (null (range 1 1)))
(is equal '(1 2 3 4) (range 1 5))
(is equal '(-3 -2 -1 0) (range -3 1)))
+
+(define-test (function-test take)
+ :compile-at :execute
+ (fail (take nil nil))
+ (fail (take 100 nil))
+ (fail (take nil 100))
+ (true (->> (list 1 2 3 4) (take 0) null))
+ (is equal "H" (take 1 "Hello"))
+ (is equal '(1 2) (take 2 '(1 2 3 4 5))))