Skip to content

Commit 5734356

Browse files
authored
Merge pull request #294 from sogaiu/add-count-examples
Add examples for count
2 parents f849f73 + 1ee62f1 commit 5734356

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

examples/count.janet

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# total of values for which pos? results in truthy value
2+
(count pos? [math/-inf -1 0 1 math/pi]) # -> 2
3+
4+
# multiple data structures can be handled
5+
(count (fn [x y] (neg? (+ x y))) [-1 -1 -1] [-1 0 1]) # -> 2
6+
7+
# predicate may not be applied to all values (e.g. 99)
8+
(count |(pos? (* $0 $1 $2)) [-3 -2] [-1 0 99] [3 2]) # -> 1
9+

0 commit comments

Comments
 (0)