typesafe-monads/monads/reader.py
2018-10-12 17:02:56 -04:00

16 lines
375 B
Python

from __future__ import annotations
from typing import Any, Callable, Generic, TypeVar
from .monad import Monad
T = TypeVar("T")
S = TypeVar("S")
F = Callable[[T], S]
class Reader(Monad[T]):
def __init__(self, function: F) -> None:
self.function = function
def map(self, function: F) -> Reader:
return Reader(lambda x: function(self.function(x)))