Skip to content

Instantly share code, notes, and snippets.

@ithayer
Last active December 13, 2015 20:08
Show Gist options
  • Save ithayer/4967783 to your computer and use it in GitHub Desktop.
Save ithayer/4967783 to your computer and use it in GitHub Desktop.
;; Update our 'browsers' function to print when it's run.
user> (defgraphfn browsers [raw-visitors]
(println "Running browsers on" (count raw-visitors) "visitors")
(map (fn [_] (rand-nth [:chrome :firefox :ie-9]) )
raw-visitors))
#'user/browsers
;; and run our computation graph lazily.
user> (defn all-visitors []
(run-graph-strategy
{:lazy? true}
{:raw-visitors [{:id 1} {:id 2} {:id 3}]}
compile-all browsers spends))
#'user/all-visitors
;; Execute the lazy graph computation, we don't expect any print.
user> (def result (all-visitors))
#'user/result
;; Now dereference one of the output values, and only the necessary dependencies are executed.
user> (:browsers result)
Running browsers on 3 visitors
[:chrome :firefox :firefox]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment