Stack

public struct Stack<Element>
extension Stack: Collection
extension Stack: BidirectionalCollection
extension Stack: ExpressibleByArrayLiteral
extension Stack: CustomStringConvertible
extension Stack: Additive
extension Stack: Monoid
extension Stack: Equatable where Element: Equatable

Stack structure.

Instance Properties

  • top

    Top element of Stack.

    Declaration

    Swift

    public var top: Element? { get }
  • Declaration

    Swift

    public var destructured: (Element, Stack<Element>)? { get }

    Return Value

    The top and the remaining items, if possible. Otherwise, nil.

Initializers

  • Create an empty Stack.

    Declaration

    Swift

    public init()
  • Create a Stack with the given sequence of elements.

    Declaration

    Swift

    public init<S>(_ elements: S) where Element == S.Element, S : Sequence

Instance Methods

  • Push item to end of Stack.

    Declaration

    Swift

    public mutating func push(_ item: Element)
  • Declaration

    Swift

    public func pushing(_ item: Element) -> Stack<Element>

    Return Value

    A new Stack with the given item pushed to the top.

  • Declaration

    Swift

    @discardableResult
    public mutating func pop() -> Element?

    Return Value

    Item from top of Stack if there are any. Otherwise, nil.

  • Declaration

    Swift

    public mutating func pop(amount: Int) -> Stack<Element>?

    Return Value

    Stack containing items popped from end of Stack

Collection

  • Declaration

    Swift

    public func index(after index: Int) -> Int

    Return Value

    Index after the given index.

    • Start index.

    Declaration

    Swift

    public var startIndex: Int { get }
    • End index.

    Declaration

    Swift

    public var endIndex: Int { get }
  • Declaration

    Swift

    public subscript(index: Int) -> Element { get }

    Return Value

    Element at the given index.

  • Count of elements contained herein.

    Complexity

    O(1)

    Declaration

    Swift

    public var count: Int { get }
  • Declaration

    Swift

    public func index(before index: Int) -> Int

    Return Value

    Index before the given index.

ExpressibleByArrayLiteral

CustomStringConvertible

  • Declaration

    Swift

    public var description: String { get }

    Return Value

    The printed description of this Stack.

Additive

  • Declaration

    Swift

    public static var zero: Stack<Element> { get }

    Return Value

    Empty Stack.

  • Declaration

    Swift

    public static func + (lhs: Stack, rhs: Stack) -> Stack

    Return Value

    Stack with the contents of two Stack values.

Monoid

  • Declaration

    Swift

    public static var identity: Stack<Element> { get }

    Return Value

    Empty Stack.

  • Declaration

    Swift

    public static func <> (lhs: Stack<Element>, rhs: Stack<Element>) -> Stack<Element>

    Return Value

    Composition of two of the same Semigroup type values.

Available where Element: Equatable

  • Declaration

    Swift

    public static func == (lhs: Stack, rhs: Stack) -> Bool

    Return Value

    true if two Stack values are equivalent. Otherwise false.