1
0
Fork 0
mirror of https://github.com/correl/typesafe-monads.git synced 2025-04-10 09:11:08 -09:00
typesafe-monads/tests/test_applicatives.py
2020-12-16 11:24:22 +01:00

22 lines
596 B
Python

import pytest # type: ignore
from typing import Callable, TypeVar
from monads import Applicative
from .fixtures import monad
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)
functor = ten.map(subtract)
assert six.apply(functor) == subtract * ten & six