 extension Array {
     typealias ElementCallback = Element -> Void
     typealias IndexedElementCallback = (Int, Element) -> Void
-    typealias TestCallback = (Element) -> Bool
+    typealias TestCallback = Element -> Bool
     
+    /// Convert an array of optional types to non-optional types by removing any
+    /// nil entries
+    ///
+    /// :param: array Array of optional types
+    /// :returns: A copy of the given array, typecasted with nil entries removed
+    static func compact(array: [T?]) -> [T] {
+        return array.filter { $0 != nil }.map { $0! }
+    }
+    
+    /// Return the index of the first array element equal to `item`.
+    ///
+    /// :param: item The item to search for
+    /// :returns: A zero-based index for the first matching element in the
+    ///   array, otherwise nil
     func indexOf<U: Equatable>(item: U) -> Int? {
         if item is Element {
             return find(unsafeBitCast(self, [U].self), item)

        return true
    }
    
    mutating func pop() -> Element? {
        return count > 0 ? removeAtIndex(count - 1) : nil
    }
    
    mutating func shift() -> Element? {
        return count > 0 ? removeAtIndex(0) : nil
    }
    
    mutating func fill(value: Element, count: Int) {
        for _ in 0..<count {
            append(value)
        }
    }
    
    // MARK: - Misc
    
    func chooseRandom() -> T? {
        if self.count == 0 { return nil }
        
        let index = Int(arc4random_uniform(UInt32(self.count)))
        return self[index]
    }
}

        return false
    }
    
    /// Test if all of the array elements pass a given condition.
    ///
    /// :param: test Function that takes an array element and returns true or
    ///   false
    /// :returns: True if every array element passes the test function,
    ///   otherwise false the first time an element fails the test
    func every(test: TestCallback) -> Bool {
        for item in self {
            if !test(item) { return false }
