Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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]
Loading