Skip to content

Typeclasses with several methods #83

Open
@sobolevn

Description

@sobolevn

There's a common use-case when we need to create a type-class with several methods. Like:

class Functor(Protocol[T]):
    def map(self, function: Callable[[T], Functor[V]]) -> Functor[V]:
        ...

    @classmethod
    def from_value(cls, inner_value: V) -> Functor[V]:
        ...

Currently, there's no way we can do that.

I propose something like this:

@typeclass
class Functor(Protocol[T]):
    def map(self, function: Callable[[T], Functor[V]]) -> Functor[V]:
        ...

    @classmethod
    def from_value(cls, inner_value: V) -> Functor[V]:
        ...

I am not sure how to bound it to the actual implementation.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requesthelp wantedExtra attention is needed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions