1
0
mirror of https://github.com/janet-lang/janet synced 2024-12-26 08:20:27 +00:00
janet/test/scratch.dst

35 lines
702 B
Plaintext
Raw Normal View History

2018-01-28 20:29:47 +00:00
(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))