tokencrawler/.venv/lib/python3.9/site-packages/oslash/monadic.py
2022-03-17 22:16:30 +01:00

20 lines
597 B
Python

"""Some useful Monadic functions.
This module contains some useful Monadic functions. Most functions
are extension methods to the Monad class, making them available to
subclasses that inherit from Monad.
"""
from typing import Callable, Any
from .typing import Monad
def compose(f: Callable[[Any], Monad], g: Callable[[Any], Monad]) -> Callable[[Any], Monad]:
r"""Monadic compose function.
Right-to-left Kleisli composition of two monadic functions.
(<=<) :: Monad m => (b -> m c) -> (a -> m b) -> a -> m c
f <=< g = \x -> g x >>= f
"""
return lambda x: g(x).bind(f)