Created
February 14, 2019 20:06
-
-
Save austenstrine/38f27e32dc1248d16d44f1eac1af67d5 to your computer and use it in GitHub Desktop.
A stack for gathering function names and printing them in a scope-level conscious fashion
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
struct ScopedPrintableStack: CustomStringConvertible | |
{ | |
var items = [String]() | |
var description: String | |
{ | |
var tabbedStackString:String = "" | |
for (index, string) in items.enumerated() | |
{ | |
tabbedStackString += String(repeating: "\t", count: index) + string + "\n" | |
} | |
return tabbedStackString | |
} | |
var count:Int | |
{ | |
return items.count | |
} | |
mutating func push(_ item: String) | |
{ | |
items.append(item) | |
} | |
mutating func pop() -> String | |
{ | |
return items.removeLast() | |
} | |
mutating func popToss() | |
{ | |
_ = self.pop() | |
} | |
func peek() -> String? | |
{ | |
return items.last | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Purposely made this non-generic so I won't use it for other purposes in other code, forgetting about the unique way it prints.