Skip to content

Consider adding generics support #8

Closed
@sobolevn

Description

@sobolevn

We need to be able to work with generic like List[str] or Result[str, Exception] and Maybe[int]

I propose the following API:

@typeclass
def test(instance) -> int:
    ...

@test.instance(
    Some[int], 
    predicate=lambda instance: is_successful(instance) and isinstance(instance.unwrap(), int),
)
def _test_success_int(instance: Some[int]) -> int:
     return instance.unwrap()

It should be supported on both side: types and runtime.

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