Skip to content

Add stack collection type #20

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed

Conversation

AquaGeek
Copy link

@AquaGeek AquaGeek commented Dec 4, 2015

This is mostly cribbed from the Swift book, but I figured it'd be nice to add a couple of these standard collection types to Foundation instead of everyone reimplementing them.

@harlanhaskins
Copy link
Contributor

I feel like this could just be an extension on Array

extension Array {
    mutating func push(element: Element) {
        self.append(element)
    }

    func peek() -> Element? {
        return self.last
    }

    mutating func pop() -> Element? {
        if !self.isEmpty {
            return storage.removeLast()
        } else {
            return nil
        }
    }
}

You get all the same behavior, plus it'll still conform to CollectionType and the like.

@parkera
Copy link
Contributor

parkera commented Dec 5, 2015

This pull request contains an API change, so let’s follow the Swift evolution process, starting with discussing the idea on the swift-evolution and swift-corelibs-dev lists.

@parkera parkera closed this Dec 5, 2015
atrick pushed a commit to atrick/swift-corelibs-foundation that referenced this pull request Jan 12, 2021
Update recommended toolchain to 2018-11-25-a
kateinoigakukun pushed a commit to kateinoigakukun/swift-corelibs-foundation that referenced this pull request Apr 29, 2021
Revert "Revert "Disable two tests because they fail in the CI.""

The tests are failing again
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants