Fork me on GitHub
#specter
<
2018-11-28
>
Marc O'Morain14:11:37

👋 Hi there. I’m looking for a way to author a specter path that can select a string or vector of strings. My data looks like this: (emails for the postal library).

(def m1 {:to ["" ""]
         :cc ""
         :bcc nil})

(def m2 {:to []
         :cc []
         :bcc [""]})
I want to collect all email addresses in the message, using specter/select

Marc O'Morain14:11:11

I ended up with:

(defn- has-recipients?
  "True if this email has any recipients"
  [message]
  (s/selected-any? [(s/multi-path :to :cc :bcc)
                    (s/if-path sequential? s/ALL some?)]
                   message))