Пример #1
0
 def test_memoize(self):
     state = ref.Ref(())
     e = state.modify(lambda t: t + ('modify was called', )
                      ).discard_and_then(effect.success('result')).memoize()
     double_e = e.discard_and_then(e)
     assert double_e.run(None) == 'result'
     assert state.value == ('modify was called', )
Пример #2
0
 def test_try_modify(self):
     int_ref = ref.Ref(0)
     int_ref.try_modify(lambda _: either.Left('')).either().run(None)
     assert int_ref.value == 0
     int_ref.try_modify(lambda _: either.Right(1)).run(None)
     assert int_ref.value == 1
Пример #3
0
 def test_modify(self):
     int_ref = ref.Ref(0)
     int_ref.modify(lambda _: 1).run(None)
     assert int_ref.value == 1
Пример #4
0
 def test_put(self):
     int_ref = ref.Ref(0)
     int_ref.put(1).run(None)
     assert int_ref.value == 1
Пример #5
0
 def test_get(self):
     int_ref = ref.Ref(0)
     assert int_ref.get().run(None) == 0