-
Notifications
You must be signed in to change notification settings - Fork 50
Open
Description
Motivation
The current trimmingPrefx drops the information about whether the prefix was matched. I often do something like:
if x.starts(with: "foo") { doSomething(with: x.dropFirst("foo".count)) }Proposed solution
if let y = x.trimmingPrefixOrNil("foo") { doSomething(with: y) }Would be more expressive, less error prone, and more efficient. I don't love the name; maybe something better can be found. Frankly I think trimmingPrefix would have been a better name for the functionality I want. After all if "foo" can't be trimmed off the front of x, then x with the prefix "foo" trimmed is not a thing, and nil is an appropriate response.
Alternatives considered
No response
Additional information
No response
Metadata
Metadata
Assignees
Labels
No labels