Skip to content

Instantly share code, notes, and snippets.

@aamedina
Created September 25, 2013 16:15
Show Gist options
  • Select an option

  • Save aamedina/6702055 to your computer and use it in GitHub Desktop.

Select an option

Save aamedina/6702055 to your computer and use it in GitHub Desktop.
(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