[ANN] Specter 1.0.5

177 views
Skip to first unread message

Nathan Marz

unread,
Nov 16, 2017, 2:36:43 PM11/16/17
to Clojure
Specter fills in the holes in Clojure's API for manipulating immutable data, allowing data manipulation to be done concisely and with near-optimal performance. Specter is especially powerful for working with nested and recursive data. 

Specter 1.0.5 adds `regex-nav` which navigates to substrings matching a regex. For example:

(transform (regex-nav #"<[a-zA-Z]*>") (comp str count) "Match 1 length: <m>, Match 2 length: <match>")
;; => "Match 1 length: 3, Match 2 length: 7"

Regexes implicitly convert to `regex-nav`, so the above can be written as:

(transform #"<[a-zA-Z]*>" (comp str count) "Match 1 length: <m>, Match 2 length: <match>")

The other highlight of the release is adding implicit keypath navigation for all primitive types.  Now you can write code like:

(select-any [0 "a" 1] [{"a" [1 2 3]} :b :c])
;; => 2

(transform ["a" 'b \c] inc {"a" {'b {\c 1}}})
;; => {"a" {b {\c 2}}}


Mark Engelberg

unread,
Nov 16, 2017, 2:43:08 PM11/16/17
to clojure
Thanks!

Leif

unread,
Nov 16, 2017, 10:58:57 PM11/16/17
to Clojure

Nice, thanks.

You made it sound like regex-nav only navigates to simple substring matches, which I was confused by, but I was pleased to find that it navigates to full regex matches as returned by re-seq:

(transform
  #"(\d{1,2})/(\d{1,2})/(\d{4})"
  (fn [[date d m y]] (str m "/" d "/" y))
  "4/9/1927 - 24/10/2011")
;;=> "9/4/1927 - 10/24/2011"

Just FYI, everybody.

Reply all
Reply to author
Forward
0 new messages