We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents b4809da + 400f2e4 commit 9e44e8dCopy full SHA for 9e44e8d
examples/keep.janet
@@ -1,8 +1,9 @@
1
+# returns an array of truthy results of predicate
2
+(keep identity [false :x nil true]) # -> @[:x true]
3
+
4
# keep values > 1, equivalent to filter
5
(keep (fn [x] (when (> x 1) x)) @[0 1 2 3]) # -> @[2 3]
6
7
# for all members > 2, keep the square
8
(keep (fn [x] (when (> x 2) (* x x))) [0 1 3 4 5]) # -> @[9 16 25]
9
-# operates on values in table
-(keep (fn [x] (when (> x 1) (* x x))) @{:foo 1 :bar 2 :baz 3}) # -> @[4 9]
0 commit comments