Created
September 25, 2013 16:15
-
-
Save aamedina/6702055 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| (def resource-agent | |
| (memoize | |
| (fn [url] | |
| (agent #{} | |
| :validator (fn [state] (set? state)) | |
| :error-handler #(.log js/console "ERROR: " %1 %2) | |
| :error-mode :fail)))) | |
| ;; now what's an agent? | |
| (def a (agent 0)) | |
| ;; an agent is an entity that acts on behalf of some piece of data - currying functions sent to it and applying it on its state, returning an updated agent | |
| (send a inc) | |
| ;; you can get the value of an agent by deferencing it | |
| @agent | |
| 1 | |
| (deref agent) | |
| 1 | |
| ;; @ and deref are the same thing, @ is just sugar, notice how after we sent the agent the inc function, it's new value is 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment