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

Extending Generic types

In Swift, it is possible to extend a Generic type. For instance, we can extend our Queue example struct and add new behaviors to it:

extension Queue {     func peek() -> Element? {         return elements.first     } } 

As seen in this example, we were able to use the Generic Element type in the extension.

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