Add some?, when-some, if-some for (not (nil? x)) conditions
Description
Environment
Attachments
Activity
Summarizing comments here, mailing list, Twitter, etc:
some uses a truthy comparison. some->, some->> use a not nil comparison. This difference existed in 1.5 some?/if-some/when-some follow the latter. This split is unfortunate, but existed before this addition.
not-nil?, non-nil?, nnil?, exists?, and all other alternatives I've seen mentioned were considered as options before the existing names were chosen by Rich. Many people have expressed negative feedback about the name choices and I will channel that to Rich for consideration, but ultimately the choice is his.
if-some and when-some are likely more useful than some?. In particular, it is commonly needed when reading from core.async channels where nil is a special value (but false is not).
(go
(if-some [v (<! c)]
...))
I'd like to echo Jozef Wagner's and Steve Losh's confusion here.
```
user=> (some odd? [1 2 3])
true
user=> (some? odd? [1 2 3])
ArityException Wrong number of args (2) passed to: user$some-QMARK- clojure.lang.AFn.throwArity (AFn.java:437)
```
I might expect (some?) to behave like (some), except returning a boolean instead of a logically true value, but this is clearly not the case. In no other case in the stdlib can I think of two functions which differ only by punctuation yet have completely different semantics.
```
user=> (some? [])
true
```
Given (some)'s association with sequences, I might interpret (some?) to mean "are there some elements here?"; but that's definitely wrong. Given we have (not=), (not-any?), (not-empty), and (not-every?), can we please name this function (not-nil?)? It's only three characters, but makes the interpretation unambiguously clear.
```
user=> (def x nil)
#'user/x
user=> (def y nil)
#'user/y
user=> (some? [x y])
true
user=> (when-some [x y] :i-expect-true)
nil
```
The fact that (when-some) and (if-some) behave like let bindings is, erm, quite surprising to me. The other binding conditionals have -let in their name; perhaps it would be appropriate to use -let here as well?
For that matter, is this use case all that common? I think I reach specifically for a nil? test fewer than 1 in 20 conditionals--in those cases, why not just write
```
(when-let [x (not-nil? y)]
...)
```
instead of
```
(when-some [x y]
...)
```
I'm just not convinced that this pattern is common enough to warrant the confusion of (when-some) having nothing to do with (when (some ...)), haha. What do y'all think? Have I missed some symmetry between (some?) and (some) that helps this all make sense?
New patch that adjusts when-some impl.
New patch that does not use "some?" in if-some and when-some.
Updated patch to make if-some and when-some similar to if-let and when-let.
Details
Details
Assignee
Reporter
Approval
Patch
Priority

Sometimes it is useful to have a form for non-nil conditions (as opposed to the existing logical true conditions).
Three additions to support this case:
some? - same as (not (nil? x))
if-some - like if-let, but checks (some? test) instead of test
when-some - like when-let, but checks (some? test) instead of test
Patch: clj-1343-4.patch