specter

Latest version: 1.1.3
Marc O'Morain 2018-11-28T14:21:37.079400Z

šŸ‘‹ 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 ["<mailto:to2@example.com|to2@example.com>" "<mailto:to2@example.com|to2@example.com>"]
         :cc "<mailto:cc@example.com|cc@example.com>"
         :bcc nil})

(def m2 {:to []
         :cc []
         :bcc ["<mailto:info@example.com|info@example.com>"]})
I want to collect all email addresses in the message, using specter/select

Marc O'Morain 2018-11-28T14:30:11.079900Z

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))

nathanmarz 2018-11-28T15:44:41.080200Z

@marc-omorain that's perfect

Marc O'Morain 2018-11-28T15:45:15.080400Z

Thanks!