         return nil
     }
     
-    func indexOf(condition: Element -> Bool) -> Int? {
+    /// Return the index of the first array element where the supplied function
+    /// returns true.
+    ///
+    /// :param: condition Function that takes an array element and returns true
+    ///   for a match, otherwise false
+    /// :returns: A zero-based index for the first matching element in the
+    ///   array, otherwise nil
+    func indexOf(condition: TestCallback) -> Int? {
         for (index, element) in enumerate(self) {
             if condition(element) { return index }
         }

extension Array {
    typealias ElementCallback = Element -> Void
    typealias IndexedElementCallback = (Int, Element) -> Void
    typealias TestCallback = (Element) -> Bool
    
    func indexOf<U: Equatable>(item: U) -> Int? {
        if item is Element {
            return find(unsafeBitCast(self, [U].self), item)

        return true
    }
    
    /// Return a randomly chosen element from the array
    ///
    /// :returns: A randomly chosen element, or nil if the array is empty
    func chooseRandom() -> T? {
        if self.count == 0 { return nil }
        
        let index = Int(arc4random_uniform(UInt32(self.count)))
        return self[index]
    }
    
    // MARK: - Mutating Methods
    
    /// Remove the last element from the array and return it
    ///
    /// :returns: The last element in the array, or nil if the array is empty
    mutating func pop() -> Element? {
        return count > 0 ? removeAtIndex(count - 1) : nil
    }
    
    /// Remove the first element from the array and return it
    ///
    /// :returns: The first element in the array, or nil if the array is empty
    mutating func shift() -> Element? {
        return count > 0 ? removeAtIndex(0) : nil
    }
    
    /// Add an element to the beginning of the array
    ///
    /// :param: item New item to prepend to the array
    mutating func unshift(item: T) {
        insert(item, atIndex: 0)
    }
    
    /// Add an element to the array a given number of times
    ///
    /// :param: value New element to append to the array
    /// :param: count Number of times to append the new element
    mutating func fill(value: Element, count: Int) {
        for _ in 0..<count {
            append(value)
        }
    }
}
