weavejester / medley

A lightweight library of useful Clojure functions
Eclipse Public License 1.0
870 stars 67 forks source link

Add conj-some fn #81

Closed velios closed 1 year ago

velios commented 1 year ago

Good afternoon. Thanks for your great set of tools. I wanted to know what you think about adding a conj-some feature similar to a conj-when in plumbing, but only if it's not nil, not for all falsey values . It seems enough general-purpose for me. With this can do thigs like this and this looks to me to continue the logic of your library

(reduce conj-some [] [:a (when (true? false-x) :b)]
=> [:a] ;;; not [:a nil] with regular conj
weavejester commented 1 year ago

I'm unsure if this adds enough benefit over filtering via a transducer:

(reduce conj-some [] coll)
(into [] (filter some?) coll)

The two expressions are almost the same length. Is there any other situation where this would save more than 3 characters?

velios commented 1 year ago

No, I don’t think I have more clear examples. I just didn't have the imagination to do it on transducers.