<commit_before>//
//  Result.swift
//  PureFutures
//
//  Created by <NAME> on 2/10/15.
//  Copyright (c) 2015 <NAME>. All rights reserved.
//

/**
    Used as result of computations which could 
    either complete with Success and Error cases
*/
public enum Result<T, E> {
    
    case Success(Box<T>)
    case Error(Box<E>)
    
    /// If result is Success returns value else `nil`
    public var value: T? {
        switch self {
        case .Success(let boxed):
            return boxed.value
        default:
            return nil
        }
    }
}

public extension Result {
    
    static func success(value: T) -> Result {
        return Result.Success(Box(value))
    }
    
    static func error(error: E) -> Result {
        return Result.Error(Box(error))
    }

}<commit_msg>Add map and flatMap for Result enum<commit_after>//
//  Result.swift
//  PureFutures
//
//  Created by <NAME> on 2/10/15.
//  Copyright (c) 2015 <NAME>. All rights reserved.
//

/**
    Used as result of computations which could 
    either complete with Success and Error cases
*/
public enum Result<T, E> {
    
    case Success(Box<T>)
    case Error(Box<E>)
    
    /// If result is Success returns value else `nil`
    public var value: T? {
        switch self {
        case .Success(let boxed):
            return boxed.value
        default:
            return nil
        }
    }
}

public extension Result {
    
    static func success(value: T) -> Result {
        return Result.Success(Box(value))
    }
    
    static func error(error: E) -> Result {
        return Result.Error(Box(error))
    }

}

public extension Result {
    
    func map<U>(f: T -> U) -> Result<U, E> {
        switch self {
        case .Success(let box):
            return .success(f(box.value))
        case .Error(let box):
            return .error(box.value)
        }
    }
    
    func flatMap<U>(f: T -> Result<U, E>) -> Result<U, E> {
        switch self {
        case .Success(let box):
            return f(box.value)
        case .Error(let box):
            return .error(box.value)
        }
    }
    
}
{'fraction_non_alphanumeric': 0.11865211200759374, 'fraction_numerical': 0.00854295206454675, 'mean_word_length': 1.751958224543081, 'pattern_counts': {'":': 0, '<': 18, '<?xml version=': 0, '>': 26, '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': '1516868', 'n_tokens_mistral': 666, 'n_tokens_neox': 644, 'n_words': 198}