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

isEmpty

Another common operation that LinkedList requires is a way to check whether it is empty. We can easily implement it in the following way:

var isEmpty: Bool {     switch self {     case .node(_ , _):         return false     case .end:         return true     } } 

To test this computed property, we will create an emptyLinkedList as follows:

let emptyLL = LinkedList<Int>.end print(emptyLL.isEmpty) print(functionalLinkedList.isEmpty) 

In the preceding example, the first print statement results in true and the second results in false.

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