trimPrefix(while:)

Mutates a Collection by discarding all elements at the start of it which satisfy the given predicate.

Trim.swift:61
mutating func trimPrefix(while predicate: (Element) throws -> Bool) rethrows

Parameters

predicate

A closure which determines if the element should be removed from the string.

This example uses trimPrefix(while:) to remove the white space at the beginning of the string:

let myString = "  hello, world  "
myString.trimPrefix(while: \.isWhitespace)
print(myString) // "hello, world  "