GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Typeclasses with several methods · Issue #83 · dry-python/classes

Typeclasses with several methods #83

New issue
Copy link
New issue
Copy link
Open
Open
Typeclasses with several methods#83
Copy link
Labels
enhancementNew feature or requestNew feature or requesthelp wantedExtra attention is neededExtra attention is needed

Description

@sobolevn
sobolevn
opened on Jun 24, 2020
Issue body actions

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.

Activity

  1. sobolevn
    added
    enhancementNew feature or requestNew feature or request
    help wantedExtra attention is neededExtra attention is needed
    on Jun 24, 2020
  2. sobolevn commented on Jun 27, 2020

    @sobolevn
    sobolevn
    on Jun 27, 2020
    MemberAuthor
    More actions
    @Functor.instance
    class Maybe(Generic[T]):
        def map(self, function: Callable[[T], Maybe[V]]) -> Maybe[V]:
            ...
    
        @classmethod
        def from_value(cls, inner_value: V) -> Maybe[V]:
            ...
  3. sobolevn commented on Jun 27, 2020

    @sobolevn
    sobolevn
    on Jun 27, 2020
    MemberAuthor
    More actions

    How is it different from a simple protocol?

    Reacted by Stevan Milic
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestNew feature or requesthelp wantedExtra attention is neededExtra attention is needed

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402503 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.