O'Reilly logo

Programming Kotlin by Stefan Bocutiu, Stephen Samuel

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Algebraic data types

Algebraic data types is another of those functional programming concepts that sounds complicated when you first stumble across it, but, after seeing an example or two, the mystery disappears. The term itself refers to the fact that algebra is defined as a set of things and the operations that are allowed to be performed on those things. For example, in mathematics the + operator is defined on integers to return the sum, and thus is an algebraic concept.

Therefore, an algebra for a type defines operations or functions on that type, hence the term algebraic data type. In computing languages, the term is generally applied to a closed set of composite types where those types implement the required functions. In Kotlin, we achieve ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required