Esempio n. 1
0
 def eff_flat_task(self):
     a, b = self._r
     t = Task.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: Task.now(List(Right(Just(Right(x + b)))))))
     res.value.run().should.equal(target)
Esempio n. 2
0
 def task(self, fa: F, err: str=''):
     from tryp.task import Task
     return Task.from_either(self.to_either(fa, err))
Esempio n. 3
0
 def message_data_task(self, data: Data, msg):
     return either_msg(msg.cons(Task.now(data)).unsafe_perform_sync())
Esempio n. 4
0
 def sequence(self):
     f = lambda: 3
     t = List(Task.now(1), Task.now(2), Task(f)).sequence(Task)
     t.unsafe_perform_sync().should.equal(Right(List(1, 2, 3)))
Esempio n. 5
0
 def zip(self):
     t = Task.now(1) & Task.now(2)
     t.unsafe_perform_sync().should.equal(Right((1, 2)))
Esempio n. 6
0
 def eff_flat_task_left(self):
     a, b = self._r
     t = Task.now(Left(Just(a)))
     target = Left(Just(a))
     res = t.effs(1, Either, Maybe) // (lambda x: Task.now(Right(Just(b))))
     res.value.run().should.equal(target)
Esempio n. 7
0
 def eff_flat_task_empty(self):
     t = Task.now(List(Right(Empty())))
     target = List(Right(Empty()))
     res = (t.effs(4, List, Either, Maybe, Either)
            .flat_map(lambda x: Task.now(List(Right(Just(Right(1)))))))
     res.value.run().should.equal(target)
Esempio n. 8
0
 def eff_map_task(self):
     a, b = self._r
     t = Task.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)