Imogen
Imogen

Reputation: 361

Best way in clojure to return a seq, or nil if its empty

Is there a better way to implement this?

(if (empty? a-seq)
    nil
    a-seq)

Upvotes: 3

Views: 555

Answers (2)

Imogen
Imogen

Reputation: 361

Don't know how I missed it in the docs, but not-empty does exactly that (thank you Guillermo for making me re-read the docs).

Upvotes: 6

guilespi
guilespi

Reputation: 4702

Use the function seq it does exactly that.

Upvotes: 10

Related Questions