mirror of
https://github.com/correl/typesafe-monads.git
synced 2024-11-21 19:18:42 +00:00
Remove conditional behavior of Future.pure
It was not wrapping awaitable values in a new awaitable, which is incorrect and confusing behavior.
This commit is contained in:
parent
a340cfea68
commit
e623ba0571
2 changed files with 4 additions and 18 deletions
|
@ -17,15 +17,11 @@ class Future(Monad[T]):
|
|||
self.awaitable = awaitable
|
||||
|
||||
@classmethod
|
||||
def pure(cls, value: Union[T, Awaitable[T]]) -> Future[T]:
|
||||
if isinstance(value, Awaitable):
|
||||
return Future(value)
|
||||
else:
|
||||
def pure(cls, value: T) -> Future[T]:
|
||||
async def identity(x: T) -> T:
|
||||
return x
|
||||
|
||||
async def identity(x: T) -> T:
|
||||
return x
|
||||
|
||||
return Future(identity(value))
|
||||
return Future(identity(value))
|
||||
|
||||
def map(self, function: Callable[[T], S]) -> Future[S]:
|
||||
async def map(f: Callable[[T], S], x: Awaitable[T]) -> S:
|
||||
|
|
|
@ -28,16 +28,6 @@ async def test_types() -> None:
|
|||
await sequence
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_pure_accepts_values_or_awaitables() -> None:
|
||||
async def three() -> int:
|
||||
return 3
|
||||
|
||||
a: Future[int] = Future.pure(3)
|
||||
b: Future[int] = Future.pure(three())
|
||||
assert await a == await b
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_functor_identity() -> None:
|
||||
identity: Callable[[int], int] = lambda x: x
|
||||
|
|
Loading…
Reference in a new issue