I have run into stuff like this a number of times so I feel your pain and wouldn't be against additional options.
However, this sounds like a user-space problem to me. Why empty?
and not str/blank?
, what about other predicates or even ones that look at pairs of elements etc.
One could consider join
as an aggregation, with (remove empty?)
and coll
as its inputs and could arrive at a great use for transducers. In fact, Chris Grand's xforms already has a suitable transducing context that could be used for this: x/str
Wrapping this beauty gives you:
(require '[net.cgrand.xforms :as x])
(defn str-join
"Works like a combination of str/join and x/str:
- Use str/join if you don't need to preprocess coll
- Use x/str if you need to preprocess coll but don't need a separator
- Use this function if you need both preprocessing and a separator"
[xform separator coll]
(x/str (comp xform (interpose separator)) coll))