Example #1
0
 def eff_flat_io_empty(self):
     t = IO.now(List(Right(Empty())))
     target = List(Right(Empty()))
     res = (t.effs(
         4, List, Either, Maybe,
         Either).flat_map(lambda x: IO.now(List(Right(Just(Right(1)))))))
     res.value.run().should.equal(target)
Example #2
0
 def flat_map_delay_2(self) -> None:
     v = 13
     w = 29
     x = 17
     f = _ + w
     g = _ + x
     t = IO.delay(f, v).flat_map(lambda a: IO.delay(g, a))
     t.attempt.should.contain(v + w + x)
Example #3
0
 def eff_flat_io(self):
     a, b = self._r
     t = IO.now(List(Right(Just(Right(a)))))
     target = List(Right(Just(Right(a + b))))
     res = (t.effs(
         4, List, Either, Maybe,
         Either).flat_map(lambda x: IO.now(List(Right(Just(Right(x + b))))))
            )
     res.value.run().should.equal(target)
Example #4
0
 def flat_map_delay(self) -> None:
     v = 13
     w = 29
     x = 17
     f = _ + x
     t = IO.delay(f, v).flat_map(L(IO.now)(_ + w))
     t.attempt.should.contain(v + w + x)
Example #5
0
 def flat_map_twice(self) -> None:
     v = 13
     w = 29
     x = 17
     t = (
         IO.now(v)
         .flat_map(L(IO.now)(_ + w))
         .flat_map(L(IO.now)(_ + x))
     )
     t.attempt.should.contain(v + w + x)
Example #6
0
def set_env(name: str, value: Any) -> IO[None]:
    return IO.delay(env.set, name, str(value))
Example #7
0
 def and_then(self) -> None:
     v = 7
     f = lambda: v
     t = IO.now(1).and_then(IO.delay(f))
     t.attempt.should.contain(v)
Example #8
0
 def map(self) -> None:
     v = 13
     w = 29
     t = IO.now(v).map(_ + w)
     t.attempt.should.contain(v + w)
Example #9
0
 def sequence(self) -> None:
     f = lambda: 3
     t = List(IO.now(1), IO.now(2), IO.delay(f)).sequence(IO)
     t.attempt.should.equal(Right(List(1, 2, 3)))
Example #10
0
 def zip(self) -> None:
     t = IO.now(1) & IO.now(2)
     t.attempt.should.equal(Right((1, 2)))
Example #11
0
 def eff_map_io(self):
     a, b = self._r
     t = IO.now(List(Just(a), Just(b), Empty()))
     target = List(Just(a + b), Just(b + b), Empty())
     res = t.effs(2).map(_ + b)
     res.value.run().should.equal(target)
Example #12
0
 def flat_map_now(self) -> None:
     v = 13
     w = 29
     t = IO.now(v).flat_map(L(IO.now)(_ + w))
     t.attempt.should.contain(v + w)
Example #13
0
 def suspend(self) -> None:
     v = 13
     w = 29
     f = lambda a: IO.now(a + v)
     t = IO.suspend(f, w)
     t.run().should.equal(v + w)
Example #14
0
 def delay(self) -> None:
     v = 13
     w = 29
     f = _ + v
     t = IO.delay(f, w)
     t.run().should.equal(v + w)
Example #15
0
 def now(self) -> None:
     v = 5
     t = IO.now(v)
     t.attempt.should.contain(v)
Example #16
0
 def trampoline(self) -> None:
     t = (List.range(1000).fold_left(IO.now(1))(lambda z, a: z.flat_map(IO.now, fs=Just('now'))))
     t.attempt.should.contain(1)
Example #17
0
 def suspend_map(self) -> None:
     t = IO.suspend(IO.now, 5) / (_ + 1)
     target = 'Suspend(Pure(5).map(lambda a: (lambda b: a + b)(1)))'
     str(t.step()).should.equal(target)
Example #18
0
 def pure(self, a: A) -> IO[A]:
     return IO.now(a)
Example #19
0
 def io(self, fa: F, err: str = ''):
     from amino.io import IO
     return IO.from_either(self.to_either(fa, err))
Example #20
0
 def suspend_flat_map(self) -> None:
     t = IO.suspend(IO.now, 5) // IO.now
     target = 'BindSuspend(now(5).flat_map(now))'
     str(t).should.equal(target)
Example #21
0
 def now_flat_map(self) -> None:
     t = IO.now(5) // IO.now
     target = 'Suspend(Pure(5).flat_map(now))'
     str(t).should.equal(target)
Example #22
0
 def now_map(self) -> None:
     t = IO.now(5) / (_ + 1)
     target = 'Suspend(Pure(5).map(lambda a: (lambda b: a + b)(1)))'
     str(t).should.equal(target)
     str(t.step()).should.equal('Pure(6)')
Example #23
0
 def eff_flat_io_left(self):
     a, b = self._r
     t = IO.now(Left(Just(a)))
     target = Left(Just(a))
     res = t.effs(1, Either, Maybe) // (lambda x: IO.now(Right(Just(b))))
     res.value.run().should.equal(target)
Example #24
0
 def now(self) -> None:
     str(IO.now(5)).should.equal('Pure(5)')