Last active
December 13, 2015 20:08
-
-
Save ithayer/4967783 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; 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