-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbooleans.py
38 lines (29 loc) · 886 Bytes
/
booleans.py
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
from stream import Stream
import random
class BooleanStream(Stream):
@staticmethod
def random():
'''
Returns an infinite stream of random booleans
:return: a random boolean stream
'''
return BooleanStream(Stream.generate(lambda: random.randint(0, 1) == 1))
@staticmethod
def true():
'''
Returns an infinite stream of True
:return: a True boolean stream
'''
return BooleanStream(Stream.generate(lambda: True))
@staticmethod
def false():
'''
Returns an infinite stream of False
:return: a False boolean stream
'''
return BooleanStream(Stream.generate(lambda: False))
def __init__(self, _stream):
if isinstance(_stream, Stream):
self.iterable = _stream.iterable
else:
self.iterable = _stream