Group Group Group Group Group Group Group Group Group

No clue what is going on in the collection protocol for Linked List extension page 61

Can anyone explain what each line does? I’ve understood everything in this chapter so far except for this part. I’m genuinely lost.

IMO, the implementation of “func ==” is not necessarily complicated and as confused.

My scheme:
static public func == (lhs: Index, rhs: Index) -> Bool {
return lhs.node === rhs.node

The implementation of “func <” is correct and “<” means Index lhs is on the left of Index rhs, in other words, the value pointed by lhs is before the value pointed by the rhs in the linkedlist.

demo script for clarity:

var list = LinkedList()
for i in 1…3 {
print(list, “\n”)

let nodes = sequence(first: list.startIndex.node) { $0?.next }
for node in nodes {

let indexOfNumberTwo = list.index(after: list.startIndex)
print(nodes.contains { $0 === indexOfNumberTwo.node })

The output:
1 -> 2 -> 3

Optional(1 -> 2 -> 3 )
Optional(2 -> 3 )


I believe you can understand the script if you are capable to complete the whole chapter.