-
Notifications
You must be signed in to change notification settings - Fork 4
/
README
54 lines (36 loc) · 1.35 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
A Dataflow Engine
by
Jeffrey Straszheim
This package is a dataflow engine for Clojure modeled loosely on the
"Cells" model, but using Clojure Ref's to manage state rather than
Agents.
Usage:
(def df
(build-dataflow
[
; Source cells are set by the user
(cell :source fred 1)
; Reference other cells by ?name
(cell greg (+ ?fred ?mary))
(cell joan (+ ?fred ?mary))
; Order does not matter
(cell :source mary 0)
(cell joan (* ?fred ?mary))
; Multiple joans exist, ?*name returns a collection
(cell sally (apply + ?*joan))
; validators can return exceptions. ?-name gets the old value
(cell :validator (when (number? ?-greg)
(when (<= ?greg ?-greg)
(throwf Exception "Non monotonic"))))]))
(add-cell-watcher (get-cell df 'sally)
nil
(fn [key cell o n]
(printf "sally changed from %s to %s\n" o n)))
(full-update df)
(update-values df {'fred 1 'mary 1})
(update-values df {'fred 5 'mary 1})
(update-values df {'fred 0 'mary 0}) ; Will throw Non monotonic exception
(get-value df 'fred)
(get-values df 'joan)
(get-value df 'sally)
(get-value df 'greg)