<commit_before>//
//  Performance.swift
//  JumuNordost
//
//  Created by <NAME> on 14/02/16.
//  Copyright © 2016 <NAME>. All rights reserved.
//

import Argo

struct Performance {
    let id: String
    let stageTime: NSDate
    let categoryName: String
    let ageGroup: String
    let predecessorHostName: String?
    let predecessorHostCountry: String?
    let appearances: [Appearance]
    let pieces: [Piece]
}

// MARK: - Equatable

extension Performance: Equatable {}

func ==(lhs: Performance, rhs: Performance) -> Bool {
    return lhs.id == rhs.id
}

// MARK: - Decodable

extension Performance: Decodable {
    private static func create(id: String)(stageTime: NSDate)(categoryName: String)(ageGroup: String)(predecessorHostName: String?)(predecessorHostCountry: String?)(appearances: [Appearance])(pieces: [Piece]) -> Performance {
        return Performance(
            id: id,
            stageTime: stageTime,
            categoryName: categoryName,
            ageGroup: ageGroup,
            predecessorHostName: predecessorHostName,
            predecessorHostCountry: predecessorHostCountry,
            appearances: appearances,
            pieces: pieces
        )
    }

    static func decode(json: JSON) -> Decoded<Performance> {
        return create // curry(self.init) is currently too complex to compile
            <^> json <| "id"
            <*> json <| "stage_time"
            <*> json <| "category_name"
            <*> json <| "age_group"
            <*> json <|? "predecessor_host_name"
            <*> json <|? "predecessor_host_country"
            <*> json <|| "appearances"
            <*> json <|| "pieces"
    }<commit_msg>Use Curry for decoding performances, now that the compiler can handle the complexity<commit_after>//
//  Performance.swift
//  JumuNordost
//
//  Created by <NAME> on 14/02/16.
//  Copyright © 2016 <NAME>. All rights reserved.
//

import Argo
import Curry

struct Performance {
    let id: String
    let stageTime: NSDate
    let categoryName: String
    let ageGroup: String
    let predecessorHostName: String?
    let predecessorHostCountry: String?
    let appearances: [Appearance]
    let pieces: [Piece]
}

// MARK: - Equatable

extension Performance: Equatable {}

func ==(lhs: Performance, rhs: Performance) -> Bool {
    return lhs.id == rhs.id
}

// MARK: - Decodable

extension Performance: Decodable {
    static func decode(json: JSON) -> Decoded<Performance> {
        return curry(self.init)
            <^> json <| "id"
            <*> json <| "stage_time"
            <*> json <| "category_name"
            <*> json <| "age_group"
            <*> json <|? "predecessor_host_name"
            <*> json <|? "predecessor_host_country"
            <*> json <|| "appearances"
            <*> json <|| "pieces"
    }
{'fraction_non_alphanumeric': 0.1222301644031451, 'fraction_numerical': 0.007147962830593281, 'mean_word_length': 2.4813432835820897, 'pattern_counts': {'":': 0, '<': 41, '<?xml version=': 0, '>': 30, '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': '111362', 'n_tokens_mistral': 856, 'n_tokens_neox': 821, 'n_words': 222}