From 9a129d0900f38b89f1f06ca826e2143b7c9b0dc4 Mon Sep 17 00:00:00 2001 From: sogaiu <983021772@users.noreply.github.com> Date: Wed, 9 Apr 2025 13:29:54 +0900 Subject: [PATCH] Add more examples for keep --- examples/keep.janet | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/examples/keep.janet b/examples/keep.janet index 2ee8bf5d..1cc9fdae 100644 --- a/examples/keep.janet +++ b/examples/keep.janet @@ -7,3 +7,9 @@ # for all members > 2, keep the square (keep (fn [x] (when (> x 2) (* x x))) [0 1 3 4 5]) # -> @[9 16 25] +# multiple data structures can be handled +(keep |(when (pos? (+ $0 $1)) $0) [1 2 3] [-1 1 1]) # -> @[2 3] + +# result has length <= shortest data structure (e.g. [-1 1]) +(keep |(when (neg? (* $0 $1)) $0) [-1 -2 -3] [-1 1]) # -> @[-2] +