class Free(Generic[F, A]):
"""_summary_
Args:
Generic (_type_): _description_
"""
def fmap(self, f: Callable[[A], B]) -> Free[F, B]:
return self.flatmap(lambda a: Free.pure(f(a)))
# def flatMap(fa: Free[M, A], f: A -> Free[M, B]) -> Free[M, B]:
# @staticmethod
def flatmap(self, f: Callable[[A], Free[F, B]]) -> Free[F, B]:
return FlatMap(self, f)
# def flatmap(self, f: Callable[[A], Monad[B]]) -> Free[F, B]:
# return FlatMap(self, cast(Callable[[A], Free[F, B]], f))
def ap(self, a: Free[F, D]) -> Free[F, E]:
return a.fmap(cast(Callable[[D], E], self))
# def pure(a: A) -> F[A]:
@staticmethod
def pure(a: E) -> Free[F, E]:
return Pure(a)
@staticmethod
def mempty(a: E) -> Free[F, E]:
return Pure(a)
@staticmethod
# def liftm(ma: F[A]) -> Free[F, A]:
# def liftm(fa: Any) -> Free[F, A]:
# def liftm(fa: Functor[K, E]) -> Lift[K, E]:
def liftm(fa: Functor[F, A]) -> Lift[F, A]:
return Lift(fa)
# def foldmap(self, nt: Callable[[F], G]) -> G:
@abstractmethod
def foldmap(self, nt: FunctionK[F, G]) -> Monad[G, A]: ...