Skip to content

Commit

Permalink
Add collect.
Browse files Browse the repository at this point in the history
  • Loading branch information
cmeiklejohn committed Jan 5, 2013
1 parent 91bad21 commit 6d70992
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -42,7 +42,7 @@ notE | not! | delayB |
filterE | filter! | sendBehavior |
onceE | once! | liftB
skipFirstE | | notB
collectE | | blindB
collectE | collect! | blindB
switchE | | calmB
delayE | delay!
snapshotE | snapshot!
Expand Down
5 changes: 5 additions & 0 deletions src/cljs/shafty/core.cljs
Expand Up @@ -68,6 +68,7 @@
(delay! [this interval])
(merge! [this that])
(filter! [this filter-fn])
(collect! [this init combine-fn])
(snapshot! [this that])
(constant! [this value]))

Expand Down Expand Up @@ -170,6 +171,10 @@
shafty.core.Event/SENTINEL))))]
(add-sink! this e) e))

(collect! [this init combine-fn]
(let [acc (atom init)]
(map! this (fn [x] (swap! acc (fn [] (combine-fn x @acc)))))))

(snapshot! [this that]
(let [e (event [this] (fn [me x] (deref that)))]
(add-sink! this e) e))
Expand Down

0 comments on commit 6d70992

Please sign in to comment.