Skip to content

Add examples for some #296

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 13, 2025
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
18 changes: 18 additions & 0 deletions examples/some.janet
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# pos? yielded only falsey values, so nil returned
(some pos? [math/-inf 0]) # -> nil

# first truthy result encountered is returned
(some (fn [x] (when (pos? x) x)) [1 0 -1]) # -> 1

# input data structure is empty, so nil returned
(some pos? []) # -> nil

# multiple data structures can be handled
(some (fn [x y] (neg? (* x y))) [1 1] [1 -2]) # -> true

# predicate not always called with all values (e.g. 0)
(some |(zero? (* $0 $1 $2)) [1 2] [7 8] [-2 -1 0]) # -> nil

# one of the input data structures was empty, so nil returned
(some |(pos? (+ $0 $1 $2)) [1 2 3] [7 8 9] []) # -> nil