<commit_before>//
//  Future+WhenAll.swift
//  Promis
//
//  Created by <NAME> on 14/10/2017.
//  Copyright © 2017 <NAME>. All rights reserved.
//

import Foundation

public enum FutureState<FutureType> {
    case unresolved
    case result(FutureType)
    case error(Error)
    case cancelled
    
    func getResult() -> FutureType? {
        switch self {
        case .result(let res): return res
        default: return nil
        }
    }
    
    func getError() -> Error? {
        switch self {
        case .error(let err): return err
        default: return nil
        }
    }
    
    func isCancelled() -> Bool {
        switch self {
        case .cancelled: return true
        default: return false
        }
    }
}

func ==<FutureType>(lhs: FutureState<FutureType>, rhs: FutureState<FutureType>) -> Bool {
    var equal: Bool = false
    switch (lhs, rhs) {
    case (.unresolved, .unresolved):
        equal = true
    case (.error, .error):
        equal = true
    case (.result, .result):
        equal = true
    case (.cancelled, .cancelled):
        equal = true
    default:
        break
    }
    return equal
}

func !=<FutureType>(lhs: FutureState<FutureType>, rhs: FutureState<FutureType>) -> Bool {
    return !(lhs == rhs)
}
<commit_msg>Better implementation for FutureState function. Thanks @MarcoSantarossa<commit_after>//
//  Future+WhenAll.swift
//  Promis
//
//  Created by <NAME> on 14/10/2017.
//  Copyright © 2017 <NAME>. All rights reserved.
//

import Foundation

public enum FutureState<FutureType> {
    case unresolved
    case result(FutureType)
    case error(Error)
    case cancelled
    
    func getResult() -> FutureType? {
        guard case .result(let value) = self else { return nil }
        return value
    }
    
    func getError() -> Error? {
        guard case .error(let err) = self else { return nil }
        return err
    }
    
    func isCancelled() -> Bool {
        return self == .cancelled
    }
}

func ==<FutureType>(lhs: FutureState<FutureType>, rhs: FutureState<FutureType>) -> Bool {
    var equal: Bool = false
    switch (lhs, rhs) {
    case (.unresolved, .unresolved):
        equal = true
    case (.error, .error):
        equal = true
    case (.result, .result):
        equal = true
    case (.cancelled, .cancelled):
        equal = true
    default:
        break
    }
    return equal
}

func !=<FutureType>(lhs: FutureState<FutureType>, rhs: FutureState<FutureType>) -> Bool {
    return !(lhs == rhs)
}

{'fraction_non_alphanumeric': 0.12004801920768307, 'fraction_numerical': 0.009603841536614645, 'mean_word_length': 2.1446540880503147, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 31, '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': '7368684', 'n_tokens_mistral': 794, 'n_tokens_neox': 753, 'n_words': 224}