Minor cleanup in sequences.hy
This commit is contained in:
parent
e86222c93f
commit
d2342cb69d
@ -28,10 +28,11 @@
|
|||||||
--getitem-- (fn [self n]
|
--getitem-- (fn [self n]
|
||||||
"get nth item of sequence"
|
"get nth item of sequence"
|
||||||
(if (hasattr n "start")
|
(if (hasattr n "start")
|
||||||
(if n.step
|
(genexpr (get self x) [x (range n.start n.stop
|
||||||
(genexpr (get self x) [x (range n.start n.stop n.step)])
|
(or n.step 1))])
|
||||||
(genexpr (get self x) [x (range n.start n.stop 1)]))
|
|
||||||
(do (when (neg? n)
|
(do (when (neg? n)
|
||||||
|
; Call (len) to force the whole
|
||||||
|
; sequence to be evaluated.
|
||||||
(len self))
|
(len self))
|
||||||
(if (<= n (. self high-water))
|
(if (<= n (. self high-water))
|
||||||
(get (. self cache) n)
|
(get (. self cache) n)
|
||||||
@ -55,10 +56,11 @@
|
|||||||
(setv index (inc index)))
|
(setv index (inc index)))
|
||||||
(except [_ IndexError]
|
(except [_ IndexError]
|
||||||
(len (. self cache)))))
|
(len (. self cache)))))
|
||||||
|
max-items-in-repr 10
|
||||||
--str-- (fn [self]
|
--str-- (fn [self]
|
||||||
"string representation of this sequence"
|
"string representation of this sequence"
|
||||||
(setv items (list (take 11 self)))
|
(setv items (list (take (inc self.max-items-in-repr) self)))
|
||||||
(.format (if (= (len items) 11)
|
(.format (if (> (len items) self.max-items-in-repr)
|
||||||
"[{0}, ...]"
|
"[{0}, ...]"
|
||||||
"[{0}]")
|
"[{0}]")
|
||||||
(.join ", " (map str items))))
|
(.join ", " (map str items))))
|
||||||
|
Loading…
Reference in New Issue
Block a user