Skip to content
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

String prepend methods #32

Open
elland opened this issue May 23, 2019 · 3 comments
Open

String prepend methods #32

elland opened this issue May 23, 2019 · 3 comments

Comments

@elland
Copy link
Contributor

elland commented May 23, 2019

Appending is all nice and well, but what about prepending?

Would something like that interest you?

extension String {
    mutating func prepend(_ aString: String) {
        self = aString.appending(self)
    }

    func prepending(_ aString: String) -> String {
        return aString.appending(self)
    }
}
@designatednerd
Copy link
Contributor

Yeah that seems reasonable. Although is there a mutating append that would make more sense to use than self = aString.appending(self)?

@elland
Copy link
Contributor Author

elland commented May 23, 2019

@designatednerd what would that look like?

@designatednerd
Copy link
Contributor

Ah OK, trying to come up with an example I see why that wouldn't work - you'd still have to assign aString to self since you'd be mutating aString if you just used aString.append

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

No branches or pull requests

2 participants