April 2017
Intermediate to advanced
316 pages
9h 33m
English
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.
Read now
Unlock full access