Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_stack_safety(self):
with recursion_limit(100):
sequence([Done(v) for v in range(500)]).run()
def test_sequence(self):
assert sequence([Done(v) for v in range(3)]).run() == (0, 1, 2)
def run() -> Trampoline[None]:
with open(path, mode + 'b') as f:
f.write(content)
return Done(None)
def run(self) -> A:
"""
Interpret a structure of trampolines to produce a result
Return:
result of intepreting this structure of \
trampolines
"""
trampoline = self
while not trampoline._is_done:
trampoline = trampoline._resume()
return cast(Done[A], trampoline).a
"""
Map each element in ``iterable`` by applying ``f``,
filter the results by the value returned by ``f``
and combine from left to right.
Example:
>>> filter_m(lambda v: Done(v % 2 == 0), range(3)).run()
(0, 2)
Args:
f: Function to map ``iterable`` by
iterable: Iterable to map by ``f``
Return:
`iterable` mapped and filtered by `f`
"""
return cast(Trampoline[Iterable[A]], filter_m_(Done, f, iterable))
and_then(lambda tu: Done((f(tu[0]), tu[1])))
)
return self.and_then(lambda a: Done(f(a)))
return Reader(lambda _: Done(v))
def sequence(iterable: Iterable[Trampoline[A]]) -> Trampoline[Iterable[A]]:
"""
Evaluate each `Trampoline` in `iterable` from left to right
and collect the results
Example:
>>> sequence([Done(v) for v in range(3)]).run()
(0, 1, 2)
Args:
iterable: The iterable to collect results from
Return:
``Trampoline`` of collected results
"""
return cast(Trampoline[Iterable[A]], sequence_(Done, iterable))