Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

freqs demo: removed all!/distinct!/timer* usage

  • Loading branch information...
commit 79af51e5477d15f0b5b6dc3bdac1f416846fba68 1 parent 2585582
@alandipert alandipert authored
Showing with 9 additions and 5 deletions.
  1. +9 −5 src/cljs/tailrecursion/javelin-demos/frequencies.cljs
View
14 src/cljs/tailrecursion/javelin-demos/frequencies.cljs
@@ -10,7 +10,7 @@
(:require-macros
[tailrecursion.javelin.macros :refer [cell]])
(:require
- [tailrecursion.javelin :refer [all! distinct! timer*]]
+ tailrecursion.javelin
[tailrecursion.javelin-demos.dom :refer [html! aset-in by-id form-cell]]
[tailrecursion.priority-map :refer [priority-map]]))
@@ -63,9 +63,8 @@
slider (form-cell "#ms" :type :int, :default 500)
interval (cell (if (neg? slider) slider (- 1000 slider)))
- ;; data collection
- rand (all! (timer* interval (fn [_] (rand-int @rand-max)) (rand-int @rand-max)))
- freqs (distinct! (cell (merge-with + ~(priority-map) {rand 1})))
+ ;; stem cell
+ freqs (cell '(priority-map (rand-int @rand-max) 1))
;; analysis
n-seen (cell (->> freqs vals (reduce +)))
@@ -79,6 +78,11 @@
least-frequent (cell (key (peek freqs)))
n-distinct (cell (count freqs))]
+ ;; add random numbers to stem cell
+ ((fn self []
+ (swap! freqs update-in [(rand-int @rand-max)] (fnil inc 1))
+ (.setTimeout js/window self @interval)))
+
;; display
(cell (html! "#status" "%s (interval is %s milliseconds)"
(if (neg? interval) "Stopped" "Running")
@@ -91,4 +95,4 @@
(cell (histogram! "#histogram" freqs
:bar-color "navy",
:bar-width 20,
- :bar-height 100))))
+ :bar-height 100))))
Please sign in to comment.
Something went wrong with that request. Please try again.