{"action":"created","issue":{"url":"https://api.github.com/repos/rbrush/clara-rules/issues/127","labels_url":"https://api.github.com/repos/rbrush/clara-rules/issues/127/labels{/name}","comments_url":"https://api.github.com/repos/rbrush/clara-rules/issues/127/comments","events_url":"https://api.github.com/repos/rbrush/clara-rules/issues/127/events","html_url":"https://github.com/rbrush/clara-rules/issues/127","id":109842482,"number":127,"title":"Provided accumulators should support fact retraction","user":{"login":"rbrush","id":574824,"avatar_url":"https://avatars.githubusercontent.com/u/574824?v=3","gravatar_id":"","url":"https://api.github.com/users/rbrush","html_url":"https://github.com/rbrush","followers_url":"https://api.github.com/users/rbrush/followers","following_url":"https://api.github.com/users/rbrush/following{/other_user}","gists_url":"https://api.github.com/users/rbrush/gists{/gist_id}","starred_url":"https://api.github.com/users/rbrush/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rbrush/subscriptions","organizations_url":"https://api.github.com/users/rbrush/orgs","repos_url":"https://api.github.com/users/rbrush/repos","events_url":"https://api.github.com/users/rbrush/events{/privacy}","received_events_url":"https://api.github.com/users/rbrush/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-10-05T17:04:01Z","updated_at":"2015-10-06T18:53:25Z","closed_at":null,"body":"The accumulators in clara.rules.accumulators namespace don't handle handle retraction of facts, which can lead to confusing behavior. For instance, the count accumulator won't decrement the count if one of the items it is counting is retracted from the working memory. This and others (such as c.r.a/sum, c.r.a/average, c.r.a/all, c.r.a/distinct) can be easily added by providing a retract-fn.\r\n\r\nIn the example of the count accumulator, the current code is:\r\n\r\n```clj\r\n(defn count\r\n  \"Returns an accumulator that simply counts the number of matching facts\"\r\n  []\r\n  (accumulate\r\n   :initial-value 0\r\n   :reduce-fn (fn [count value] (inc count))\r\n   :combine-fn +))\r\n```\r\n\r\nWe simply need to add a retract-fn like this:\r\n\r\n```clj\r\n   :retract-fn (fn [count retracted] (dec count))\r\n```"},"comment":{"url":"https://api.github.com/repos/rbrush/clara-rules/issues/comments/145964319","html_url":"https://github.com/rbrush/clara-rules/issues/127#issuecomment-145964319","issue_url":"https://api.github.com/repos/rbrush/clara-rules/issues/127","id":145964319,"user":{"login":"mrrodriguez","id":3483575,"avatar_url":"https://avatars.githubusercontent.com/u/3483575?v=3","gravatar_id":"","url":"https://api.github.com/users/mrrodriguez","html_url":"https://github.com/mrrodriguez","followers_url":"https://api.github.com/users/mrrodriguez/followers","following_url":"https://api.github.com/users/mrrodriguez/following{/other_user}","gists_url":"https://api.github.com/users/mrrodriguez/gists{/gist_id}","starred_url":"https://api.github.com/users/mrrodriguez/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mrrodriguez/subscriptions","organizations_url":"https://api.github.com/users/mrrodriguez/orgs","repos_url":"https://api.github.com/users/mrrodriguez/repos","events_url":"https://api.github.com/users/mrrodriguez/events{/privacy}","received_events_url":"https://api.github.com/users/mrrodriguez/received_events","type":"User","site_admin":false},"created_at":"2015-10-06T18:53:25Z","updated_at":"2015-10-06T18:53:25Z","body":"I think this issue strongly related to\r\nhttps://github.com/rbrush/clara-rules/issues/86\r\n\r\nWhich I don't think we ever really came to a resolution on. \r\nPerhaps reading that will give you some background devn. "}}