specter

Latest version: 1.1.3
h0bbit 2021-04-08T04:16:23.011300Z

@nathanmarz: thanks for the tip, changing to vtransformed brings it down to 163.9 µs. The implementation code is beyond me at the moment, so I simply created the following in my namespace:

(s/defdynamicnav vtransformed
  "Navigates to a view of the current value by transforming it with the
   specified path and update-fn."
  [path update-fn]
  (s/late-bound-nav [late (s/late-path path)
                     late-fn update-fn]
                    (select* [this structure next-fn]
                             (next-fn (s/compiled-vtransform late late-fn structure)))
                    (transform* [this structure next-fn]
                                (next-fn (s/compiled-vtransform late late-fn structure)))))
Results are correct across all versions of the parser. Latest parser looks like this:
(s/select [s/ALL :systems s/ALL :containers s/ALL
             (vtransformed [(s/collect-one :name) :dependencies s/ALL]
                           (fn [[c] d]
                              {:container c
                               :dependency (:name d)
                               :transports (:transport d)
                               :entities (:data_entity d '())}))
             :dependencies s/ALL]
            yaml-data)

nathanmarz 2021-04-08T05:28:01.011800Z

@h0bbit looking at it again it looks like you actually want a version of view that lets you look at collected values at the same time

nathanmarz 2021-04-08T05:29:29.012100Z

then you could write:

(s/select [s/ALL :systems s/ALL :containers s/ALL
           (s/collect-one :name) :dependencies s/ALL
           (my-view
             (fn [[c] d]
              {:container c
               :dependency (:name d)
               :transports (:transport d)
               :entities (:data_entity d '())}
               ))]
           yaml-data)

nathanmarz 2021-04-08T05:31:58.012800Z

my-view would be:

(defrichnav my-view
  [afn]
  (select* [this vals structure next-fn]
    (next-fn [] (afn vals structure)))
  (transform* [this vals structure next-fn]
    (next-fn [] (afn vals structure))))

nathanmarz 2021-04-08T05:33:09.013200Z

seems like that should be much faster

h0bbit 2021-04-08T06:05:22.014Z

@nathanmarz: wow, that brought it down to 87.3 µs. Thanks. I have loads to learn and think about with this library!

h0bbit 2021-04-08T06:06:34.014700Z

I’ll study some more to get a better understanding of views and when to use them