Skip to content

Commit 9e44e8d

Browse files
authored
Merge pull request #259 from sogaiu/swap-keep-examples
Swap an example for keep
2 parents b4809da + 400f2e4 commit 9e44e8d

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

examples/keep.janet

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1+
# returns an array of truthy results of predicate
2+
(keep identity [false :x nil true]) # -> @[:x true]
3+
14
# keep values > 1, equivalent to filter
25
(keep (fn [x] (when (> x 1) x)) @[0 1 2 3]) # -> @[2 3]
36

47
# for all members > 2, keep the square
58
(keep (fn [x] (when (> x 2) (* x x))) [0 1 3 4 5]) # -> @[9 16 25]
69

7-
# operates on values in table
8-
(keep (fn [x] (when (> x 1) (* x x))) @{:foo 1 :bar 2 :baz 3}) # -> @[4 9]

0 commit comments

Comments
 (0)