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

Size

To make this BST a little more complete, let's implement a property to check for its size:

var size: Int {     switch self {     case .leaf:         return 0     case .node(let lhs, _, let rhs):         return 1 + lhs.size + rhs.size     } } 

This computed property is going to provide the size of the BST, and we can use it as follows:

print(functionalBST.size) // prints "3" 

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