Skip to content

Commit 7050669

Browse files
committed
Modified the queue's peek property name to front per naming design guidelines. Computed properties should not imply action. Also checks out on Knuth's Fundamental Algorithms book page 241 where front and rear is the choice for his wording.
1 parent 3c5a105 commit 7050669

File tree

3 files changed

+5
-15
lines changed

3 files changed

+5
-15
lines changed

Queue/Queue.playground/Contents.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public struct Queue<T> {
3434
}
3535
}
3636

37-
public var peek: T? {
37+
public var front: T? {
3838
return array.first
3939
}
4040
}
@@ -56,7 +56,7 @@ queueOfNames.dequeue()
5656

5757
// Return the first element in the queue.
5858
// Returns "Lisa" since "Carl" was dequeued on the previous line.
59-
queueOfNames.peek
59+
queueOfNames.front
6060

6161
// Check to see if the queue is empty.
6262
// Returns "false" since the queue still has elements in it.

Queue/Queue.playground/timeline.xctimeline

Lines changed: 0 additions & 6 deletions
This file was deleted.

Queue/README.markdown

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public struct Queue<T> {
6868
}
6969
}
7070

71-
public func peek() -> T? {
71+
public var front: T? {
7272
return array.first
7373
}
7474
}
@@ -166,12 +166,8 @@ public struct Queue<T> {
166166
return element
167167
}
168168

169-
public func peek() -> T? {
170-
if isEmpty {
171-
return nil
172-
} else {
173-
return array[head]
174-
}
169+
public var front: T? {
170+
return array.first
175171
}
176172
}
177173
```

0 commit comments

Comments
 (0)