mirror of
https://github.com/correl/typesafe-monads.git
synced 2024-11-28 19:19:55 +00:00
16 lines
375 B
Python
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)))
|