I\'m looking to create a function that operates very closely to filter
// swap and return pivot
extension Array
{
// return pivot
mutating func swapIf(predicate: (Element) -> Bool) -> Int
{
var pivot = 0
for i in 0..<self.count
{
if predicate( self[i] )
{
if i > 0
{
swap(&self[i], &self[pivot])
}
pivot += 1
}
}
return pivot
}
}
This is my code and the concept is.. reduce memory usage.
I checked that 'swapIf' is 4-times faster than 'removeIf'.