Type Class, a Scala language concept
Last updated
Type classes are one of Scala's most important super-powers: they enable you to add new behaviour to existing classes, without modifying those classes. In many languages, to add a behaviour to a class, you would typically extend it with an interface, and then implement methods against this interface.This, however, does not scale: especially when you have older libraries, you would be forced to make them depend on a new interface, and have to re-build everything.
Type classes are used heavily in Apple's SwiftUI as "extensions" to enable powerful abstraction capabilities.
Type classes enable you to do things like this:
There's more!
To see the rest of the Scala concept, and all our other concepts for free, Register (free).