🔥 Burn Fat Fast. Discover How! 💪

My new article is out! It is all about typeclasses in Python a | Opensource Findings

My new article is out! It is all about typeclasses in Python and dry-python/classes.

Today I am explaining what typeclasses are and how to use them. I give examples in 4 very different languages: #rust, #elixir, #haskell, and #python to show that this concept is universal.

I am also showing that this idea is very pythonic by comparing our classes implementation with functools.singledispatch. There are lots of different details!

Check how easy it is to define a typeclass with classes:

from classes import AssociatedType, Supports, typeclass

class Greet(AssociatedType):
"""Special type to represent that some instance can `greet`."""

@typeclass(Greet)
def greet(instance) -> str:
"""No implementation needed."""

@greet.instance(str)
def _greet_str(instance: str) -> str:
return 'Hello, {0}!'.format(instance)

def greet_and_print(instance: Supports[Greet]) -> None:
print(greet(instance))

greet_and_print('world')

Check it out!