GithubHelp home page GithubHelp logo

Comments (2)

hozumi avatar hozumi commented on August 16, 2024 1

Thank you for explanation.

Because I currently use my fork which solved #3 , unfortunately the suggested code does not work for me in the situation described in #3 .

I think that as input nodes is also node, to include them in result map seems natural and harmless.
To make no distinction between input nodes and normal nodes has additional benefit.
A caller could intercept an intermediate node by feeding the node as input.

(def lazy-stat
  (graph/lazy-compile {:a (pl/fnk [] 1)
                       :b (pl/fnk [a] a)
                       :c (pl/fnk [b] b)}))
(:c (lazy-stat {:b 2}))
; => 2  (imaginary result)

But I don't know internal details and tradeoff, so don't be mind.
Thanks.

from plumbing.

w01fe avatar w01fe commented on August 16, 2024

Unless you have a strong argument for this, I don't think we'll change the default behavior. But you can easily achieve this by wrapping your compiled graph with a higher-order function:

user> (require '[plumbing.graph :as graph] '[plumbing.core :as plumbing] '[plumbing.map :as map] '[plumbing.fnk.pfnk :as pfnk])
nil
user> (defn merge-inputs [f]
  (pfnk/fn->fnk
   (fn [m] (merge m (f m)))
   [(pfnk/input-schema f)
    (merge (pfnk/output-schema f)
           (map/keep-leaves identity (pfnk/input-schema f)))]))
#'user/merge-inputs
user> (def merged-lazy-stat (merge-inputs (graph/lazy-compile {:a (plumbing/fnk [x] (+ x 1))})))
#'user/merged-lazy-stat
user> (merged-lazy-stat {:x 3})
{:a 4, :x 3}

You could even make your own compile functions that do this automatically, if that's what you want:

(def my-lazy-compile (comp merge-inputs graph/lazy-compile))

(Feel free to use this code however you wish.) Does this satisfy your need?

from plumbing.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.