Fork me on GitHub
#specter
<
2021-04-08
>
h0bbit04:04:23

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

nathanmarz05:04:01

@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

nathanmarz05:04:29

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)

nathanmarz05:04:58

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

nathanmarz05:04:09

seems like that should be much faster

h0bbit06:04:22

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

h0bbit06:04:34

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