Skip to content

Id

Id dataclass

Bases: Generic[A]

Id is a Monad.

Source code in funclift/types/id.py
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
@dataclass
class Id(Generic[A]):
    """Id is a [`Monad`][funclift.monad.Monad]."""
    a: A

    def fmap(self, f: Callable[[A], B]) -> Id[B]:
        return Id(f(self.a))

    @staticmethod
    def pure(b: B) -> Id[B]:
        return Id(b)

    def ap(self: Id[Callable[[C], E]], other: Id[C]) -> Id[E]:
        # return Id(self.a(other.a))
        return other.fmap(self.a)

    def flatmap(self, f: Callable[[A], Id[B]]) -> Id[B]:
        return f(self.a)