Skip to content

Commit

Permalink
Swap an example for keep
Browse files Browse the repository at this point in the history
  • Loading branch information
sogaiu committed Jan 17, 2025
1 parent b4809da commit 400f2e4
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions examples/keep.janet
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# returns an array of truthy results of predicate
(keep identity [false :x nil true]) # -> @[:x true]

# keep values > 1, equivalent to filter
(keep (fn [x] (when (> x 1) x)) @[0 1 2 3]) # -> @[2 3]

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

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

0 comments on commit 400f2e4

Please sign in to comment.