typesafe-monads/tests/test_applicatives.py

22 lines
574 B
Python
Raw Permalink Normal View History

2018-10-12 18:09:16 +00:00
import pytest # type: ignore
2018-10-12 21:02:17 +00:00
from typing import Callable, TypeVar
2018-10-12 18:09:16 +00:00
2018-10-12 21:02:17 +00:00
from monads import Applicative
from .fixtures import monad
2018-10-12 18:09:16 +00:00
T = TypeVar("T")
S = TypeVar("S")
def test_fmap_using_ap(monad) -> None:
f: Callable[[int], int] = lambda x: x + 1
m: Applicative[int] = monad.pure(3)
assert m.map(f) == m.apply(monad.pure(f))
def test_apply_and_operator(monad) -> None:
subtract: Callable[[int], Callable[[int], int]] = lambda x: lambda y: x - y
ten = monad.pure(10)
six = monad.pure(6)
assert six.apply(ten.map(subtract)) == subtract * ten & six