<commit_before>import Foundation

class AccountsFileReader {

  class func read(_ path: URL) -> [String] {
    do {
      let contents = try String(contentsOf: path)
      return parseEntries(from: contents)
    } catch {
      print(error)
      return []
    }
  }
  
  private class func parseEntries(from input: String) -> [String] {
    let accounts = input.components(separatedBy: "\n")
    let numberOfAccounts: Int = accounts.count
    
    var entries = [String]()
    
    for start in stride(from: 0, to: numberOfAccounts, by: EntryReader.linesPerEntry) {
      let end = min(start + EntryReader.linesPerEntry, numberOfAccounts)
      let account = Array(accounts[start..<end])
      
      if let entry = EntryReader.read(account) {
        entries.append(entry)
      }
    }
    
    return entries
  }

}<commit_msg>Extract accounts stride creation and use flatMap<commit_after>import Foundation

class AccountsFileReader {

  class func read(_ path: URL) -> [String] {
    do {
      let contents = try String(contentsOf: path)
      return parseEntries(from: contents)
    } catch {
      print(error)
      return []
    }
  }
  
  private class func parseEntries(from input: String) -> [String] {
    let accounts = input.components(separatedBy: "\n")
    let numberOfAccounts: Int = accounts.count
    
    return slice(accounts).flatMap { start in
      let end = min(start + EntryReader.linesPerEntry, numberOfAccounts)
      let account = Array(accounts[start..<end])
      
      return EntryReader.read(account)
    }
  }
  
  class func slice(_ accounts: [String]) -> StrideTo<Int> {
    return stride(from: 0, to: accounts.count, by: EntryReader.linesPerEntry)
  }

}
{'fraction_non_alphanumeric': 0.1050767414403778, 'fraction_numerical': 0.0011806375442739079, 'mean_word_length': 2.8435374149659864, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 9, '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': '796276', 'n_tokens_mistral': 511, 'n_tokens_neox': 504, 'n_words': 134}