How to Reverse a Linked List in Swift
Robert Cottrell
171

How do you feel about taking advantage of default parameters to do something like this:

public func reversed(head: LinkedList<Element>? = nil, 
tail: LinkedList<Element> = .empty) ->
LinkedList<Element>
{
let head = head ?? self
switch head {
case .empty:
return tail
case .list(let element, let nextItem):
return reversed(head: nextItem, tail: .list(element, tail))
}
}