O'Reilly logo
  • yuchen zhan thinks this is interesting:

In order to push the items you get from sequence onto the stack, you need to guarantee that the type of the items coming from the sequence matches the type of the stack’s elements.


Cover of Swift Programming: The Big Nerd Ranch Guide


'where' clause next to generic parameters is deprecated in Swift3, the example code should be now:

func pushItemsOntoStack<Element, S: Sequence>( stack: inout Stack<Element>, fromSequence sequence: S) where S.Iterator.Element == Element {
for item in sequence {
stack.push(newItem: item)