1    type Atom<T>
2        def bind (f : T -> Unit) =
3            f value
4            subscribe { _ x -> f x }
5    
6        def map<U> (f : T -> U) =
7            let atom = Atom<U> (f value)
8            let token = subscribe { _ x -> atom.set (f x) @[weak atom] }
9            atom.push_token token
10   
11           atom.as_readonly
12   
13       def bind_revert (f : T -> Unit) (g : T -> Unit) =
14           f value
15           let token = subscribe { prev_x x ->
16                                       g prev_x
17                                       f x }
18           Token { g value
19                   token.discard }
20