let inline filter (f: ^T -> bool) (array: ( ^T)[]) = if array = null then invalidArg "array" "Array can not be null." if array.Length = 0 then invalidArg "array" "Array can not be empty." let mutable count = 0 for i = 0 to array.Length-1 do if f array.[i] then count <- count + 1 let result = Array.zeroCreate count let mutable j = 0 for i = 0 to array.Length-1 do if f array.[i] then result.[j] <- array.[i] j <- j + 1 result