mirror of
https://github.com/correl/typesafe-monads.git
synced 2024-11-21 19:18:42 +00:00
WIP: Reader
This commit is contained in:
parent
63aec9aa75
commit
ca7a2366b2
2 changed files with 17 additions and 0 deletions
|
@ -3,3 +3,4 @@ from .applicative import Applicative
|
|||
from .monad import Monad
|
||||
from .maybe import Maybe, Just, Nothing
|
||||
from .result import Result, Ok, Err
|
||||
from .reader import Reader
|
||||
|
|
16
monads/reader.py
Normal file
16
monads/reader.py
Normal file
|
@ -0,0 +1,16 @@
|
|||
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)))
|
Loading…
Reference in a new issue