-
Notifications
You must be signed in to change notification settings - Fork 7
/
stream.go
41 lines (36 loc) · 930 Bytes
/
stream.go
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
package gologic
func mzero () *Stream {
return nil
}
func unit (a S) *Stream {
var x = new(Stream)
x.first = a
x.rest = func () *Stream {
return mzero()
}
return x
}
func choice (a S, s func () *Stream) *Stream {
var x = new(Stream)
x.first = a
x.rest = s
return x
}
func stream_concat(s1 *Stream, s2 func () *Stream) *Stream {
if s1 == mzero() {
return s2()
} else {
return choice(s1.first, func () *Stream {
return stream_concat(s1.rest(), s2)
})
}
}
func stream_interleave (s1 *Stream, s2 *Stream) *Stream {
if s1 == mzero() {
return s2
} else {
return choice(s1.first, func () *Stream {
return stream_interleave(s2,s1.rest())
})
}
}