Skip to content

Commit

Permalink
Merge pull request #261 from erichaney/examples_accumulate
Browse files Browse the repository at this point in the history
Add examples for accumulate and accumulate2
  • Loading branch information
sogaiu authored Feb 2, 2025
2 parents dd5788b + 67d7627 commit 8c76285
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
8 changes: 8 additions & 0 deletions examples/accumulate.janet
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
(reduce + 0 [1 2 3 4]) # -> 10
(accumulate + 0 [1 2 3 4]) # -> @[1 3 6 10]

(reduce + 0 []) # -> 0
(accumulate + 0 []) # -> @[]

(reduce string "" ["J" "a" "n" "e" "t"]) # -> "Janet"
(accumulate string "" ["J" "a" "n" "e" "t"]) # -> @["J" "Ja" "Jan" "Jane" "Janet"]
8 changes: 8 additions & 0 deletions examples/accumulate2
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
(reduce2 + [1 2 3 4]) # -> 10
(accumulate2 + [1 2 3 4]) # -> @[1 3 6 10]

(reduce2 + []) # -> nil
(accumulate2 + []) # -> @[]

(reduce2 max [1 4 2 3 9 5]) # -> 9
(accumulate2 max [1 4 2 3 9 5]) # -> @[1 4 4 4 9 9]

0 comments on commit 8c76285

Please sign in to comment.