Skip to content

Instantly share code, notes, and snippets.

@austenstrine
Created February 14, 2019 20:06
Show Gist options
  • Save austenstrine/38f27e32dc1248d16d44f1eac1af67d5 to your computer and use it in GitHub Desktop.
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
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
}
}
@austenstrine
Copy link
Author

Purposely made this non-generic so I won't use it for other purposes in other code, forgetting about the unique way it prints.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment