IG
Size: a a a
IG
M
IG
ВК
IG
extension Array {
@discardableResult
mutating func pop<T>(to type: T.Type) -> Self {
if let index = firstIndex(where: { $0 is T }) {
removeLast(count - index - 1)
}
return self
}
}
M
IG
M
extension Array {
@discardableResult
mutating func pop<T>(to type: T.Type) -> Self {
if let index = firstIndex(where: { $0 is T }) {
return Array(self[...index])
}
return self
}
}
ВК
M
extension Array {
@discardableResult
func pop<T>(to type: T.Type) -> ArraySlice<Element> {
if let index = firstIndex(where: { $0 is T }) {
return self[...index]
}
return ArraySlice(self)
}
}
M
extension Array {
func pop<T>(to type: T.Type) -> ArraySlice<Element>? {
if let index = firstIndex(where: { $0 is T }) {
return self[...index]
}
return nil
}
}
M
M
extension Array {
func pop<T>(to _: T.Type) -> ArraySlice<Element>? {
firstIndex(where: { $0 is T })
.map { self[...$0] }
}
}
M
ВК
M
ВК
M
M
func pop<T>(to _: T.Type) -> ArraySlice<Element>? {
prefix(while: { !($0 is T) })
}
IG
func pop<T>(to _: T.Type) -> ArraySlice<Element>? {
prefix(while: { !($0 is T) })
}