1
0
mirror of https://github.com/janet-lang/janet synced 2024-12-25 16:00:27 +00:00
janet/test/scratch.dst
2018-01-28 15:29:47 -05:00

35 lines
702 B
Plaintext

(def mapnil
" (mapnil f a)
Map a function over a tuple or array and return nil."
(fn [f t]
(var i 0)
(def len (length t))
(while (< i len)
(f (get t i))
(varset! i (+ i 1)))))
(def mapt
" (mapt f t)
Map a function over a tuple or array and produce a new tuple."
(fn [f t]
(var i 0)
(def len (length t))
(def accum [])
(while (< i len)
(array-push accum (f (get t i)))
(varset! i (+ i 1)))
(apply tuple accum)))
(def mapa
" (mapa f a)
Map a function over a tuple or array and produce a new array."
(fn [f t]
(var i 0)
(def len (length t))
(def accum [])
(while (< i len)
(array-push accum (f (get t i)))
(varset! i (+ i 1)))
accum))