<commit_before>//
//  JSONValue.swift
//  Tyro
//
//  Created by <NAME> on 11/17/15.
//  Copyright © 2015 TypeLift. All rights reserved.
//

import Foundation
import Swiftz

public enum JSONValue {
    case Array([JSONValue])
    case Object([Swift.String: JSONValue])
    case String(Swift.String)
    case Number(NSNumber)
    case Null
}

extension JSONValue: CustomStringConvertible {
    public var description: Swift.String {
        switch self {
        case .Array(let values):
            return "JSONValue(Array(\(values)))"
        case .Object(let value):
            return "JSONValue(Object(\(value)))"
        case .String(let value):
            return "JSONValue(String(\(value)))"
        case .Number(let value):
            return "JSONValue(Number(\(value)))"
        case .Null:
            return "JSONValue(Null)"
        }
    }
}

extension JSONValue: Equatable {}

public func == (lhs: JSONValue, rhs: JSONValue) -> Bool {
    switch (lhs, rhs) {
    case (.Array(let lhsValues), .Array(let rhsValues)):
        return lhsValues == rhsValues
    case (.Object(let lhsValue), .Object(let rhsValue)):
        return lhsValue == rhsValue
    case (.String(let lhsValue), .String(let rhsValue)):
        return lhsValue == rhsValue
    case (.Number(let lhsValue), .Number(let rhsValue)):
        return lhsValue == rhsValue
    case (.Null, .Null):
        return true
    default:
        return false
    }
}

public func == (lhs: JSONValue?, rhs: JSONValue?) -> Bool {
    if let lhs = lhs, rhs = rhs {
        return lhs == rhs
    }
    
    return false
}

extension JSONValue {
    var array: [JSONValue]? {
        switch self {
        case .Array(let values): return values
        default: return nil
        }
    }
    
    var object: [Swift.String: JSONValue]? {
        switch self {
        case .Object(let value): return value
        default: return nil
        }
    }
    
    var string: Swift.String? {
        switch self {
        case .String(let value): return value
        default: return nil
        }
    }
    
    var number: NSNumber? {
        switch self {
        case .Number(let value): return value
        default: return nil
        }
    }
    
    var null: NSNull? {
        switch self {
        case .Null: return NSNull()
        default: return nil
        }
    }
    
    var anyObject: AnyObject? {
        switch self {
        case .Array(let values): return values as? AnyObject
        case .Object(let value): return value as? AnyObject
        case .String(let s): return s
        case .Number(let n): return n
        case .Null: return NSNull()
        default: return nil
        }
    }
}

extension JSONValue {
    func value<A: FromJSON where A.T == A>() -> A? {
        return A.fromJSON(self).right
    }

    func valueEither<A: FromJSON where A.T == A>() -> Either<JSONError, A> {
        return A.fromJSON(self)
    }
    
    func value<A: FromJSON where A.T == A>() -> [A]? {
        return FromJSONArray<A, A>.fromJSON(self).right
    }
    
    func valueEither<A: FromJSON where A.T == A>() -> Either<JSONError, [A]> {
        return FromJSONArray<A, A>.fromJSON(self)
    }
    
    func value<A: FromJSON where A.T == A>() -> [Swift.String: A]? {
        return FromJSONDictionary<A, A>.fromJSON(self).right
    }

    func valueEither<A: FromJSON where A.T == A>() -> Either<JSONError, [Swift.String: A]> {
        return FromJSONDictionary<A, A>.fromJSON(self)
    }<commit_msg>Removed default case<commit_after>//
//  JSONValue.swift
//  Tyro
//
//  Created by <NAME> on 11/17/15.
//  Copyright © 2015 TypeLift. All rights reserved.
//

import Foundation
import Swiftz

public enum JSONValue {
    case Array([JSONValue])
    case Object([Swift.String: JSONValue])
    case String(Swift.String)
    case Number(NSNumber)
    case Null
}

extension JSONValue: CustomStringConvertible {
    public var description: Swift.String {
        switch self {
        case .Array(let values):
            return "JSONValue(Array(\(values)))"
        case .Object(let value):
            return "JSONValue(Object(\(value)))"
        case .String(let value):
            return "JSONValue(String(\(value)))"
        case .Number(let value):
            return "JSONValue(Number(\(value)))"
        case .Null:
            return "JSONValue(Null)"
        }
    }
}

extension JSONValue: Equatable {}

public func == (lhs: JSONValue, rhs: JSONValue) -> Bool {
    switch (lhs, rhs) {
    case (.Array(let lhsValues), .Array(let rhsValues)):
        return lhsValues == rhsValues
    case (.Object(let lhsValue), .Object(let rhsValue)):
        return lhsValue == rhsValue
    case (.String(let lhsValue), .String(let rhsValue)):
        return lhsValue == rhsValue
    case (.Number(let lhsValue), .Number(let rhsValue)):
        return lhsValue == rhsValue
    case (.Null, .Null):
        return true
    default:
        return false
    }
}

public func == (lhs: JSONValue?, rhs: JSONValue?) -> Bool {
    if let lhs = lhs, rhs = rhs {
        return lhs == rhs
    }
    
    return false
}

extension JSONValue {
    var array: [JSONValue]? {
        switch self {
        case .Array(let values): return values
        default: return nil
        }
    }
    
    var object: [Swift.String: JSONValue]? {
        switch self {
        case .Object(let value): return value
        default: return nil
        }
    }
    
    var string: Swift.String? {
        switch self {
        case .String(let value): return value
        default: return nil
        }
    }
    
    var number: NSNumber? {
        switch self {
        case .Number(let value): return value
        default: return nil
        }
    }
    
    var null: NSNull? {
        switch self {
        case .Null: return NSNull()
        default: return nil
        }
    }
    
    var anyObject: AnyObject? {
        switch self {
        case .Array(let values): return values as? AnyObject
        case .Object(let value): return value as? AnyObject
        case .String(let s): return s
        case .Number(let n): return n
        case .Null: return NSNull()
        }
    }
}

extension JSONValue {
    func value<A: FromJSON where A.T == A>() -> A? {
        return A.fromJSON(self).right
    }

    func valueEither<A: FromJSON where A.T == A>() -> Either<JSONError, A> {
        return A.fromJSON(self)
    }
    
    func value<A: FromJSON where A.T == A>() -> [A]? {
        return FromJSONArray<A, A>.fromJSON(self).right
    }
    
    func valueEither<A: FromJSON where A.T == A>() -> Either<JSONError, [A]> {
        return FromJSONArray<A, A>.fromJSON(self)
    }
    
    func value<A: FromJSON where A.T == A>() -> [Swift.String: A]? {
        return FromJSONDictionary<A, A>.fromJSON(self).right
    }

    func valueEither<A: FromJSON where A.T == A>() -> Either<JSONError, [Swift.String: A]> {
        return FromJSONDictionary<A, A>.fromJSON(self)
    }
{'fraction_non_alphanumeric': 0.12282217422606191, 'fraction_numerical': 0.0028797696184305254, 'mean_word_length': 2.0599118942731276, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 47, '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': '5589600', 'n_tokens_mistral': 2146, 'n_tokens_neox': 2082, 'n_words': 609}