O'Reilly logo

Swift Functional Programming - Second Edition by Dr. Fatih Nayebi

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

Pattern matching

Programming languages that support algebraic data types often support a set of features to work with fields of composite types or variants of a type. These features are essential in defining functions to operate on different fields or variants in a type-safe manner.

One such feature is called pattern matching, that enables us to define functions that operate differently on each of a type's variants and extract individual fields from a composite type while maintaining the language's type safety guarantees.

In fact, the compilers of many languages with pattern matching will issue warnings or errors if we do not handle all of a type's fields or variants properly. These warnings help us write safer and more robust code.

The following ...

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