Skip to content

Commit

Permalink
Merge pull request kodecocodes#444 from TheIronBorn/patch-8
Browse files Browse the repository at this point in the history
prettify some syntax around optionals
  • Loading branch information
kelvinlauKL authored Apr 25, 2017
2 parents 0cf2f36 + 7ecbb71 commit 862209b
Showing 1 changed file with 5 additions and 23 deletions.
28 changes: 5 additions & 23 deletions AVL Tree/AVLTree.playground/Sources/AVLTree.swift
Original file line number Diff line number Diff line change
Expand Up @@ -99,17 +99,11 @@ open class AVLTree<Key: Comparable, Payload> {

extension TreeNode {
public func minimum() -> TreeNode? {
if let leftChild = self.leftChild {
return leftChild.minimum()
}
return self
return leftChild?.minimum() ?? self
}

public func maximum() -> TreeNode? {
if let rightChild = self.rightChild {
return rightChild.maximum()
}
return self
return rightChild?.maximum() ?? self
}
}

Expand All @@ -120,11 +114,7 @@ extension AVLTree {
}

public func search(input: Key) -> Payload? {
if let result = search(key: input, node: root) {
return result.payload
} else {
return nil
}
return search(key: input, node: root)?.payload
}

fileprivate func search(key: Key, node: Node?) -> Node? {
Expand Down Expand Up @@ -385,11 +375,7 @@ extension TreeNode: CustomDebugStringConvertible {

extension AVLTree: CustomDebugStringConvertible {
public var debugDescription: String {
if let root = root {
return root.debugDescription
} else {
return "[]"
}
return root?.debugDescription ?? "[]"
}
}

Expand All @@ -409,10 +395,6 @@ extension TreeNode: CustomStringConvertible {

extension AVLTree: CustomStringConvertible {
public var description: String {
if let root = root {
return root.description
} else {
return "[]"
}
return root?.description ?? "[]"
}
}

0 comments on commit 862209b

Please sign in to comment.