Skip to content

Commit a5cf6b7

Browse files
author
Mac Bellingrath
committed
removes redundant case let ? statements from workspace
1 parent 9ad55ca commit a5cf6b7

File tree

6 files changed

+23
-23
lines changed

6 files changed

+23
-23
lines changed

Binary Search Tree/README.markdown

+6-6
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ Searching is a recursive process, but you can also implement it with a simple lo
267267
```swift
268268
public func search(value: T) -> BinarySearchTree? {
269269
var node: BinarySearchTree? = self
270-
while case let n? = node {
270+
while let n = node {
271271
if value < n.value {
272272
node = n.left
273273
} else if value > n.value {
@@ -391,15 +391,15 @@ We also need a function that returns the minimum and maximum of a node:
391391
```swift
392392
public func minimum() -> BinarySearchTree {
393393
var node = self
394-
while case let next? = node.left {
394+
while let next = node.left {
395395
node = next
396396
}
397397
return node
398398
}
399399

400400
public func maximum() -> BinarySearchTree {
401401
var node = self
402-
while case let next? = node.right {
402+
while let next = node.right {
403403
node = next
404404
}
405405
return node
@@ -471,7 +471,7 @@ You can also calculate the *depth* of a node, which is the distance to the root.
471471
public func depth() -> Int {
472472
var node = self
473473
var edges = 0
474-
while case let parent? = node.parent {
474+
while let parent = node.parent {
475475
node = parent
476476
edges += 1
477477
}
@@ -503,7 +503,7 @@ The `predecessor()` function returns the node whose value precedes the current v
503503
return left.maximum()
504504
} else {
505505
var node = self
506-
while case let parent? = node.parent {
506+
while let parent = node.parent {
507507
if parent.value < value { return parent }
508508
node = parent
509509
}
@@ -524,7 +524,7 @@ The code for `successor()` works the same way but mirrored:
524524
return right.minimum()
525525
} else {
526526
var node = self
527-
while case let parent? = node.parent {
527+
while let parent = node.parent {
528528
if parent.value > value { return parent }
529529
node = parent
530530
}

Binary Search Tree/Solution 1/BinarySearchTree.playground/Sources/BinarySearchTree.swift

+6-6
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ extension BinarySearchTree {
155155
*/
156156
public func search(value: T) -> BinarySearchTree? {
157157
var node: BinarySearchTree? = self
158-
while case let n? = node {
158+
while let n = node {
159159
if value < n.value {
160160
node = n.left
161161
} else if value > n.value {
@@ -189,7 +189,7 @@ extension BinarySearchTree {
189189
*/
190190
public func minimum() -> BinarySearchTree {
191191
var node = self
192-
while case let next? = node.left {
192+
while let next = node.left {
193193
node = next
194194
}
195195
return node
@@ -200,7 +200,7 @@ extension BinarySearchTree {
200200
*/
201201
public func maximum() -> BinarySearchTree {
202202
var node = self
203-
while case let next? = node.right {
203+
while let next = node.right {
204204
node = next
205205
}
206206
return node
@@ -213,7 +213,7 @@ extension BinarySearchTree {
213213
public func depth() -> Int {
214214
var node = self
215215
var edges = 0
216-
while case let parent? = node.parent {
216+
while let parent = node.parent {
217217
node = parent
218218
edges += 1
219219
}
@@ -240,7 +240,7 @@ extension BinarySearchTree {
240240
return left.maximum()
241241
} else {
242242
var node = self
243-
while case let parent? = node.parent {
243+
while let parent = node.parent {
244244
if parent.value < value { return parent }
245245
node = parent
246246
}
@@ -256,7 +256,7 @@ extension BinarySearchTree {
256256
return right.minimum()
257257
} else {
258258
var node = self
259-
while case let parent? = node.parent {
259+
while let parent = node.parent {
260260
if parent.value > value { return parent }
261261
node = parent
262262
}

LRU Cache/LRUCache.playground/Sources/LinkedList.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public final class LinkedList<T> {
2626

2727
public var last: Node? {
2828
if var node = head {
29-
while case let next? = node.next {
29+
while let next = node.next {
3030
node = next
3131
}
3232
return node
@@ -38,7 +38,7 @@ public final class LinkedList<T> {
3838
public var count: Int {
3939
if var node = head {
4040
var c = 1
41-
while case let next? = node.next {
41+
while let next = node.next {
4242
node = next
4343
c += 1
4444
}

Linked List/LinkedList.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public final class LinkedList<T> {
2626

2727
public var last: Node? {
2828
if var node = head {
29-
while case let next? = node.next {
29+
while let next = node.next {
3030
node = next
3131
}
3232
return node
@@ -38,7 +38,7 @@ public final class LinkedList<T> {
3838
public var count: Int {
3939
if var node = head {
4040
var c = 1
41-
while case let next? = node.next {
41+
while let next = node.next {
4242
node = next
4343
c += 1
4444
}

Linked List/README.markdown

+3-3
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ Let's also add a property that gives you the last node in the list. This is wher
109109
```swift
110110
public var last: Node? {
111111
if var node = head {
112-
while case let next? = node.next {
112+
while let next = node.next {
113113
node = next
114114
}
115115
return node
@@ -121,7 +121,7 @@ Let's also add a property that gives you the last node in the list. This is wher
121121

122122
If you're new to Swift, you've probably seen `if let` but maybe not `if var`. It does the same thing -- it unwraps the `head` optional and puts the result in a new local variable named `node`. The difference is that `node` is not a constant but an actual variable, so we can change it inside the loop.
123123

124-
The loop also does some Swift magic. The `while case let next? = node.next` bit keeps looping until `node.next` is nil. You could have written this as follows:
124+
The loop also does some Swift magic. The `while let next = node.next` bit keeps looping until `node.next` is nil. You could have written this as follows:
125125

126126
```swift
127127
var node: Node? = head
@@ -198,7 +198,7 @@ Let's add a method to count how many nodes are in the list. This will look very
198198
public var count: Int {
199199
if var node = head {
200200
var c = 1
201-
while case let next? = node.next {
201+
while let next = node.next {
202202
node = next
203203
c += 1
204204
}

Threaded Binary Tree/ThreadedBinaryTree.playground/Sources/ThreadedBinaryTree.swift

+4-4
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ extension ThreadedBinaryTree {
217217
*/
218218
public func search(_ value: T) -> ThreadedBinaryTree? {
219219
var node: ThreadedBinaryTree? = self
220-
while case let n? = node {
220+
while let n = node {
221221
if value < n.value {
222222
node = n.left
223223
} else if value > n.value {
@@ -252,7 +252,7 @@ extension ThreadedBinaryTree {
252252
*/
253253
public func minimum() -> ThreadedBinaryTree {
254254
var node = self
255-
while case let next? = node.left {
255+
while let next = node.left {
256256
node = next
257257
}
258258
return node
@@ -263,7 +263,7 @@ extension ThreadedBinaryTree {
263263
*/
264264
public func maximum() -> ThreadedBinaryTree {
265265
var node = self
266-
while case let next? = node.right {
266+
while let next = node.right {
267267
node = next
268268
}
269269
return node
@@ -276,7 +276,7 @@ extension ThreadedBinaryTree {
276276
public func depth() -> Int {
277277
var node = self
278278
var edges = 0
279-
while case let parent? = node.parent {
279+
while let parent = node.parent {
280280
node = parent
281281
edges += 1
282282
}

0 commit comments

Comments
 (0)