Re-implemented last function so that it also supports iterators. Added a test to reflect this.
This commit is contained in:
parent
0496b7f7b6
commit
d1ed8f49d3
@ -245,7 +245,7 @@
|
|||||||
|
|
||||||
(defn last [coll]
|
(defn last [coll]
|
||||||
"Return last item from `coll`"
|
"Return last item from `coll`"
|
||||||
(nth coll (- (len coll) 1)))
|
(get (list coll) -1))
|
||||||
|
|
||||||
(defn list* [hd &rest tl]
|
(defn list* [hd &rest tl]
|
||||||
"Return a dotted list construed from the elements of the argument"
|
"Return a dotted list construed from the elements of the argument"
|
||||||
|
@ -386,6 +386,8 @@
|
|||||||
"NATIVE: testing the last function"
|
"NATIVE: testing the last function"
|
||||||
(assert-equal (last [1 2 3 4]) 4)
|
(assert-equal (last [1 2 3 4]) 4)
|
||||||
(assert-equal (last [5]) 5))
|
(assert-equal (last [5]) 5))
|
||||||
|
(import itertools)
|
||||||
|
(assert-equal (last (take 5 (itertools.count 10))) 14)
|
||||||
|
|
||||||
(defn test-neg []
|
(defn test-neg []
|
||||||
"NATIVE: testing the neg? function"
|
"NATIVE: testing the neg? function"
|
||||||
|
Loading…
Reference in New Issue
Block a user