From 1ee62f1ebe23ab8feabf0f55f945e5558112a7e0 Mon Sep 17 00:00:00 2001 From: sogaiu <983021772@users.noreply.github.com> Date: Wed, 9 Apr 2025 14:31:45 +0900 Subject: [PATCH] Add examples for count --- examples/count.janet | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 examples/count.janet diff --git a/examples/count.janet b/examples/count.janet new file mode 100644 index 0000000..aaf0914 --- /dev/null +++ b/examples/count.janet @@ -0,0 +1,9 @@ +# total of values for which pos? results in truthy value +(count pos? [math/-inf -1 0 1 math/pi]) # -> 2 + +# multiple data structures can be handled +(count (fn [x y] (neg? (+ x y))) [-1 -1 -1] [-1 0 1]) # -> 2 + +# predicate may not be applied to all values (e.g. 99) +(count |(pos? (* $0 $1 $2)) [-3 -2] [-1 0 99] [3 2]) # -> 1 +