New Perc Version Released (#%) with "Path Expressions"

Wadup y’all - got some new play stuffs for you to bang on!

As a reminder, perc is an anonymous function syntax for humans that makes associative sugar a first class sweetener among our more traditional, indexical confections.

This version introduces path expressions that allow you to do really concise slicing and dicing of deeply nested collections:

(->> [{:a {:z {:x 5}}
       :b {:c {:p {:q 6}}}}
      {:a {:z {:x 7}}
        :b {:c {:p {:q 8}}}}
      {:a {:z {:x 9}}
        :b {:c {:p {:q 10}}}}]

     (mapv #%{:a {:z {:x (inc %:a:z:x)}}
              :b {:c {:p {:q (dec %:b:c:p:q)}}}})

     (reduce #%{:a {:z {:x (+ %1:a:z:x %2:a:z:x)}}
                :b {:c {:p {:q (+ %1:b:c:p:q %2:b:c:p:q)}}}}))
; => {:a {:z {:x 24}}, :b {:c {:p {:q 21}}}}

We also have in this release thread functions for more easily integrating percs into -> threads:

(-> {:z/x {:y [1 'b :c 8 {::s/a {:num 9}}]}}

    #%> %:z/x:y

    #%>(+ %1 %5:*s/a:num)) 
; => 10

Notice how we first navigated down into the common branch between the two values we wanted to operate on and then defined those subsequent paths from that common branch.

In this release we’ve also elided the namespace (%/) from our tag literals and consolidated on only %-like tokens, so as not to squat on ? and $.

To get started, head on over to the quick start instructions and try it out!

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.