-
Notifications
You must be signed in to change notification settings - Fork 0
/
timeline.fs
41 lines (35 loc) · 1.09 KB
/
timeline.fs
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
namespace Timeline
module Timeline =
type Timeline<'a> =
{ mutable lastVal: 'a
mutable _fns: list<'a -> unit> }
let Timeline =
fun a ->
{ lastVal = a
_fns = [] }
let nextT =
fun a timeline ->
timeline.lastVal <- a // mutable
timeline._fns
|> List.iter (fun f -> f a) //perform all fns in the list
timeline // return the modified timeline
let bindT =
fun monadf timelineA ->
let timelineB = timelineA.lastVal |> monadf
let newFn =
fun a ->
timelineB
|> nextT (a |> monadf).lastVal
|> ignore
timelineA._fns <- timelineA._fns @ [ newFn ]
timelineB
//----------------------------------------------
let mapT =
fun f -> (f >> Timeline) |> bindT
//==============================================================
let log = // 'a -> unit
fun a -> printfn "%A" a
let logT =
fun a ->
log a
Timeline a