Hi Tim,

your getArg function is actually a nice use case
of a not very often used of condp: :>>.

Please note in the following example: as David
Nolen said, we have to use seq after re-seq since
re-seq doesn't return a nil but the empty list.
Hence I used comp to chain the two together.
Also incorporated the suggestions of David Sletten
to use \w and \S.

Another thing I noticed: you put the docstring
after the argument vector. That's wrong. In Clojure
the docstring has to be in front of the argument
vector.

(defn get-arg
  "Docstring goes here!"
  [arg]
  (condp (comp seq re-seq) arg
    #"[+](\w+)"    :>> #(vector (-> % first (nth 1) keyword) true)
    #"[-](\w+)"    :>> #(vector (-> % first (nth 1) keyword) false)
    #"(\w+)=(\S+)" :>> #(let [x (first %)]
                          [(keyword (nth x 1)) (nth x 2)])
    [:files arg]))

Maybe one could also merge the first two cases, but well...

Hope this helps.

Sincerely
Meikel

Attachment: smime.p7s
Description: S/MIME cryptographic signature

Reply via email to