1
0
mirror of https://github.com/janet-lang/janet synced 2025-11-02 00:23:02 +00:00

Add accumulate(2) and reduce2

These functions are variations on reduce and can be quite useful.
Improve error message for jpm as well.
This commit is contained in:
Calvin Rose
2020-03-26 21:35:11 -05:00
parent a3a45511e5
commit 3eb0927a2b
4 changed files with 50 additions and 2 deletions

View File

@@ -181,4 +181,14 @@
(def c (unmarshal (marshal b)))
(assert (= 2 (c 1)) "marshal-on-stack-closure 1"))
# Reduce2
(assert (= (reduce + 0 (range 1 10)) (reduce2 + (range 10))) "reduce2 1")
(assert (= (reduce * 1 (range 2 10)) (reduce2 * (range 1 10))) "reduce2")
# Accumulate
(assert (deep= (accumulate + 0 (range 5)) @[0 1 3 6 10]) "accumulate 1")
(assert (deep= (accumulate2 + (range 5)) @[0 1 3 6 10]) "accumulate2 1")
(end-suite)