<commit_before>//
//  Animal.swift
//  AnimalBrowser
//
//  Created by <NAME> on 12/06/2015.
//  Copyright © 2015 <NAME>. All rights reserved.
//

import Foundation

final class AnimalDataSource {
    var animals: [Animal] = {
        guard let path = NSBundle.mainBundle().pathForResource("Animals", ofType: "plist"),
            animalArray = NSArray(contentsOfFile: path) else {return []}
        
        var array = [Animal]()
        
        for a in animalArray {
            guard let name = a["name"] as? String,
                latinName = a["species"] as? String,
                text = a["text"] as? String,
                authorName = a["authorName"] as? String,
                authorPhotoName = a["authorPhoto"] as? String else {continue}
            
            let imageName = a["photo"] as? String
            
            array.append(Animal(name: name,
                latinName: latinName,
                text: text,
                imageName: imageName,
                authorName: authorName,
                authorPhotoName: authorPhotoName))
        }
        
        return array.sort{$0 < $1}
        }()
}

struct Animal {
    let name: String
    let latinName: String
    let text: String
    let imageName: String? // some animals don't have photos
    let authorName: String
    let authorPhotoName: String
}

extension Animal: Comparable {}

func ==(lhs: Animal, rhs: Animal) -> Bool {
    return lhs.name == rhs.name
}

func <=(lhs: Animal, rhs: Animal) -> Bool {
    return lhs.name <= rhs.name
}

func <(lhs: Animal, rhs: Animal) -> Bool {
    return lhs.name < rhs.name
}

func >=(lhs: Animal, rhs: Animal) -> Bool {
    return lhs.name >= rhs.name
}<commit_msg>Updated to use map instead of for loop.<commit_after>//
//  Animal.swift
//  AnimalBrowser
//
//  Created by <NAME> on 12/06/2015.
//  Copyright © 2015 <NAME>. All rights reserved.
//

import Foundation

final class AnimalDataSource {
    var animals: [Animal] = {
        guard let path = NSBundle.mainBundle().pathForResource("Animals", ofType: "plist"),
            animalArray = NSArray(contentsOfFile: path) as? [[String: String]] else {return []}

        return animalArray.map {
            a in
            return Animal(name: a["name"]!,
                latinName: a["species"]!,
                text: a["text"]!,
                imageName: a["photo"],
                authorName: a["authorName"]!,
                authorPhotoName: a["authorPhoto"]!)
        }.sort{$0 < $1}
    }()
}

struct Animal {
    let name: String
    let latinName: String
    let text: String
    let imageName: String? // some animals don't have photos
    let authorName: String
    let authorPhotoName: String
}

extension Animal: Comparable {}

func ==(lhs: Animal, rhs: Animal) -> Bool {
    return lhs.name == rhs.name
}

func <=(lhs: Animal, rhs: Animal) -> Bool {
    return lhs.name <= rhs.name
}

func <(lhs: Animal, rhs: Animal) -> Bool {
    return lhs.name < rhs.name
}

func >=(lhs: Animal, rhs: Animal) -> Bool {
    return lhs.name >= rhs.name
}
{'fraction_non_alphanumeric': 0.12942332896461337, 'fraction_numerical': 0.009174311926605505, 'mean_word_length': 2.108961303462322, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 19, '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': '783133', 'n_tokens_mistral': 958, 'n_tokens_neox': 896, 'n_words': 276}