Hi all, I am quite interested in using plumbing in one of my projects and have the feeling that it is a perfect fit and indeed a better solution to something I have written before. I can't, however, quite figure out the best way to translate what I have into an implementation that uses graphs.
Consider a function such as: (defn reducekv-fun [m] (let [m (reduce-kv (fn [ret k v] (let [first-result (map inc v) ret (assoc ret :first-result first-result) ret (assoc ret :second-result (map #(- % 2) (get ret :first-result))) ret (assoc-in ret [:third-result k] (map #(* 2 %) v))] ret)) m (get m :foo))] m)) where m would be something like {:foo {:first-set #{a b c} :second-set #{a b c}}}. I want to keep keys present in m, but "update" some of them. Which is something that I use in some places in my current codebase. It essentially tries to model a graph and uses a map to move data from one computation "node" to another. I don't really like this approach because it is hard to change the actual implementation that is being called, there is no verficiation that all necessary keys are present and it feels made up on the spot. plumbing/graph looks as if it would fit perfectly. I think that it should be pretty easy to translate this into an implementation that uses plumbing's graphs, but I am running into problems with call like ret (assoc-in ret [:third-result k] (map #(* 2 %) v)) and am simply not sure how to handle them elegantly. What I would like to be able to do in the end is: * Replace the entire computation by a call to a single function (rather "hook" that returns a map that can be merged with the old map * An easy way to compose that hook, essentially by adding multiple "subgraphs" together. My basic idea is to have something like (but feel free to suggest something completely different): (defn reducekv-fun [m hook-function] (let [m (reduce-kv (fn [ret k v] (hook-function ret k v)) m (get m :foo))] m)) And the ability to define the computation as combination of multiple subgraphs in the sense of (invalid code, but you get the idea): (def compute1-graph { :first-result (fnk [v] (map inc v)) :second-result (fnk [first-result] (map #(- % 2) first-result))}) (def compute2-graph { :third-result {k (fnk [v] (map #(* 2 %) v))}}) (def hook-function (fn [???] ... (graph/???-compile (merge compute1-graph compute2-graph … compute5-graph)))) But I have problems with nested dynamic keys (such as the k in compute2-graph) and am also not sure if this whole approach is a good idea. It looks as if your library is *exactly* what I need, but I am stuck at making the first step without breaking everything. Thanks a lot! -- Wolodja <babi...@gmail.com> 4096R/CAF14EFC 081C B7CD FF04 2BA9 94EA 36B2 8B7F 7D30 CAF1 4EFC
signature.asc
Description: Digital signature