mirror of
https://github.com/janet-lang/janet
synced 2024-11-25 01:37:19 +00:00
update interleave
, interpose
This commit is contained in:
parent
51c0cf97bc
commit
9cf674cdcb
@ -966,7 +966,6 @@
|
|||||||
1 (map-n 1 ,maptype ,res ,f ,ind ,inds)
|
1 (map-n 1 ,maptype ,res ,f ,ind ,inds)
|
||||||
2 (map-n 2 ,maptype ,res ,f ,ind ,inds)
|
2 (map-n 2 ,maptype ,res ,f ,ind ,inds)
|
||||||
3 (map-n 3 ,maptype ,res ,f ,ind ,inds)
|
3 (map-n 3 ,maptype ,res ,f ,ind ,inds)
|
||||||
4 (map-n 4 ,maptype ,res ,f ,ind ,inds)
|
|
||||||
(do
|
(do
|
||||||
(def iter-keys (array/new-filled ninds))
|
(def iter-keys (array/new-filled ninds))
|
||||||
(def call-buffer (array/new-filled ninds))
|
(def call-buffer (array/new-filled ninds))
|
||||||
@ -1472,8 +1471,8 @@
|
|||||||
(do
|
(do
|
||||||
(var n (length t))
|
(var n (length t))
|
||||||
(def ret (if (bytes? t)
|
(def ret (if (bytes? t)
|
||||||
(buffer/new-filled n)
|
(buffer/new-filled n)
|
||||||
(array/new-filled n)))
|
(array/new-filled n)))
|
||||||
(each v t
|
(each v t
|
||||||
(put ret (-- n) v))
|
(put ret (-- n) v))
|
||||||
ret)
|
ret)
|
||||||
@ -1666,14 +1665,7 @@
|
|||||||
(defn interleave
|
(defn interleave
|
||||||
"Returns an array of the first elements of each col, then the second elements, etc."
|
"Returns an array of the first elements of each col, then the second elements, etc."
|
||||||
[& cols]
|
[& cols]
|
||||||
(def res @[])
|
(mapcat tuple ;cols))
|
||||||
(def ncol (length cols))
|
|
||||||
(when (> ncol 0)
|
|
||||||
(def len (min ;(map length cols)))
|
|
||||||
(loop [i :range [0 len]
|
|
||||||
ci :range [0 ncol]]
|
|
||||||
(array/push res (in (in cols ci) i))))
|
|
||||||
res)
|
|
||||||
|
|
||||||
(defn distinct
|
(defn distinct
|
||||||
"Returns an array of the deduplicated values in `xs`."
|
"Returns an array of the deduplicated values in `xs`."
|
||||||
@ -1720,14 +1712,23 @@
|
|||||||
``Returns a sequence of the elements of `ind` separated by
|
``Returns a sequence of the elements of `ind` separated by
|
||||||
`sep`. Returns a new array.``
|
`sep`. Returns a new array.``
|
||||||
[sep ind]
|
[sep ind]
|
||||||
(def len (length ind))
|
(var k (next ind nil))
|
||||||
(def ret (array/new (- (* 2 len) 1)))
|
(if (not= nil k)
|
||||||
(if (> len 0) (put ret 0 (in ind 0)))
|
(if (lengthable? ind)
|
||||||
(var i 1)
|
(do
|
||||||
(while (< i len)
|
(def ret (array/new-filled (- (* 2 (length ind)) 1) sep))
|
||||||
(array/push ret sep (in ind i))
|
(var i 0)
|
||||||
(++ i))
|
(while (not= nil k)
|
||||||
ret)
|
(put ret i (in ind k))
|
||||||
|
(set k (next ind k))
|
||||||
|
(+= i 2))
|
||||||
|
ret)
|
||||||
|
(do
|
||||||
|
(def ret @[(in ind k)])
|
||||||
|
(while (not= nil (set k (next ind k)))
|
||||||
|
(array/push ret sep (in ind k)))
|
||||||
|
ret))
|
||||||
|
@[]))
|
||||||
|
|
||||||
(defn partition
|
(defn partition
|
||||||
``Partition an indexed data structure `ind` into tuples
|
``Partition an indexed data structure `ind` into tuples
|
||||||
@ -2893,8 +2894,8 @@
|
|||||||
(try
|
(try
|
||||||
(printf pf x)
|
(printf pf x)
|
||||||
([e]
|
([e]
|
||||||
(eprintf "bad pretty format %v: %v" pf e)
|
(eprintf "bad pretty format %v: %v" pf e)
|
||||||
(eflush)))
|
(eflush)))
|
||||||
(flush))
|
(flush))
|
||||||
(do
|
(do
|
||||||
(debug/stacktrace f x "")
|
(debug/stacktrace f x "")
|
||||||
|
Loading…
Reference in New Issue
Block a user