I ran into this code which is part of a Swift implementation of a linked list in the Swift Algorithm Club. Throughout the implementation the author uses case let
following a while statement right before unwrapping an optional. I've never seen the case keyword used outside of the context of a switch statement, and I'm wondering what exactly it does? Does it somehow cast the let next? = node.next
part to true or false, maybe depending on whether next?
becomes nil or not?
public var last: Node? {
if var node = head {
while case let next? = node.next {
node = next
}
return node
} else {
return nil
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With