<commit_before>//
//  Array.swift
//  ZamzamKit
//
//  Created by <NAME> on 3/16/16.
//  Copyright © 2016 Zamzam. All rights reserved.
//

import Foundation

public extension Array {
    
    public func take(count: Int) -> [Element] {
        var to: [Element] = []
        var i = 0
        while i < self.count && i < count {
            to.append(self[i])
            i += 1
        }
        return to
    }
    
    public func drop(count: Int) -> [Element] {
        var to: [Element] = []
        var i = count
        while i < self.count {
            to.append(self[i])
            i += 1
        }
        return to
    }
    
    public func get(index: Int) -> Element? {
        return self.indices.contains(index)
            ? self[index] : nil
    }
    
    public func closestMatch(index: Int, predicate: (Element) -> Bool) -> (Int, Element)? {
        if predicate(self[index]) {
            return (index, self[index])
        }
        
        var delta = 1
        
        while(true) {
            guard index + delta < count || index - delta >= 0 else {
                return nil
            }
            
            if index + delta < count && predicate(self[index + delta]) {
                return (index + delta, self[index + delta])
            }
            
            if index - delta >= 0 && predicate(self[index - delta]) {
                return (index - delta, self[index - delta])
            }
            
            delta = delta + 1
        }
    }

}<commit_msg>Added remove each array extension.<commit_after>//
//  Array.swift
//  ZamzamKit
//
//  Created by <NAME> on 3/16/16.
//  Copyright © 2016 Zamzam. All rights reserved.
//

import Foundation

public extension Array {
    
    /**
     Take a specified amount of elements.

     - parameter count: Number of elements to retrieve.

     - returns: Elements that specify the count number.
     */
    public func take(count: Int) -> [Element] {
        var to: [Element] = []
        var i = 0
        while i < self.count && i < count {
            to.append(self[i])
            i += 1
        }
        return to
    }

    /**
     Drop a specified amount of elements.

     - parameter count: Number of elements to drop.

     - returns: Elements that are left over.
     */
    public func drop(count: Int) -> [Element] {
        var to: [Element] = []
        var i = count
        while i < self.count {
            to.append(self[i])
            i += 1
        }
        return to
    }
    
    /**
     Optional element by indice.

     - parameter index: Indice of the array element.

     - returns: An optional element.
     */
    public func get(index: Int) -> Element? {
        return self.indices.contains(index)
            ? self[index] : nil
    }
    
    public func closestMatch(index: Int, predicate: (Element) -> Bool) -> (Int, Element)? {
        if predicate(self[index]) {
            return (index, self[index])
        }
        
        var delta = 1
        
        while(true) {
            guard index + delta < count || index - delta >= 0 else {
                return nil
            }
            
            if index + delta < count && predicate(self[index + delta]) {
                return (index + delta, self[index + delta])
            }
            
            if index - delta >= 0 && predicate(self[index - delta]) {
                return (index - delta, self[index - delta])
            }
            
            delta = delta + 1
        }
    }
    
    /**
     Remove array items in a thread-safe manner.

     - parameter handler: Handler with array item that was popped.
     */
    public mutating func removeEach(handler: Element -> Void) -> Void {
        self.enumerate().reverse().forEach { item in
            handler(self.removeAtIndex(item.index))
        }
    }

}
{'fraction_non_alphanumeric': 0.11322228006246747, 'fraction_numerical': 0.008328995314940135, 'mean_word_length': 1.364923076923077, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1052738', 'n_tokens_mistral': 1113, 'n_tokens_neox': 1050, 'n_words': 329}