Using the code as it is given in the book, the code below throws error: “cannot specialize a non-generic definition”. I am not sure what I am missing out on.
50> struct Stack<Element> {
51. var items = [Element]()
52.
53. mutating func push(_ newItem: Element) {
54. items.append(newItem)
55. }
56.
57. mutating func pop() -> Element? {
58. guard !items.isEmpty else { return nil }
59. return items.removeLast()
60. }
61.
62. func map<U>(_ f: (Element) -> U) -> Stack<U> {
63. var mappedItems = [U]()
64. for item in items {
65. mappedItems.append(f(item))
66. }
67. return Stack<U>(items: mappedItems)
68. }
69. }
error: repl.swift:67:16: error: cannot specialize a non-generic definition
Help appreciated. Swift V4, using Swift REPL. Book 2nd ed.