<commit_before>//
//  AsyncType+Debug.swift
//  BrightFutures
//
//  Created by Oleksii on 23/09/2016.
//  Copyright © 2016 <NAME>. All rights reserved.
//

import Result

public protocol LoggerType {
    func log(message: String)
}

struct Logger: LoggerType {
    func log(message: String) {
        print(message)
    }
}

public extension AsyncType where Value: ResultProtocol {
    public func debug(logger: LoggerType = Logger(), context c: @escaping ExecutionContext = DefaultThreadingModel(), messageBlock: @escaping (Self.Value) -> String) -> Self {
        return andThen(context: c, callback: { result in
            logger.log(message: messageBlock(result))
        })
    }
}

extension String {
    var lastPathComponent: String {
        return characters.split(separator: "/").lazy.last.flatMap({ String($0) }) ?? self
    }
}<commit_msg>Add debug func with identifier<commit_after>//
//  AsyncType+Debug.swift
//  BrightFutures
//
//  Created by Oleksii on 23/09/2016.
//  Copyright © 2016 <NAME>. All rights reserved.
//

import Result

public protocol LoggerType {
    func log(message: String)
}

struct Logger: LoggerType {
    func log(message: String) {
        print(message)
    }
}

public extension AsyncType where Value: ResultProtocol {
    public func debug(logger: LoggerType = Logger(), context c: @escaping ExecutionContext = DefaultThreadingModel(), messageBlock: @escaping (Self.Value) -> String) -> Self {
        return andThen(context: c, callback: { result in
            logger.log(message: messageBlock(result))
        })
    }
    
    public func debug(_ identifer: String? = nil, logger: LoggerType = Logger(), file: String = #file, line: UInt = #line, function: String = #function, context c: @escaping ExecutionContext = DefaultThreadingModel()) -> Self {
        return debug(logger: logger, context: c, messageBlock: { result -> String in
            let messageBody: String
            let resultString = result.analysis(ifSuccess: { _ in "succeeded" } , ifFailure: { _ in "failed" })
            
            if let identifer = identifer {
                messageBody = "Future \(identifer)"
            } else {
                messageBody = "\(file.lastPathComponent) at line \(line), func: \(function) - future"
            }
            
            return "\(messageBody) \(resultString)"
        })
    }
}

extension String {
    var lastPathComponent: String {
        return characters.split(separator: "/").lazy.last.flatMap({ String($0) }) ?? self
    }
}
{'fraction_non_alphanumeric': 0.12157330154946365, 'fraction_numerical': 0.010329757647993643, 'mean_word_length': 2.713864306784661, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 11, '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': '4104707', 'n_tokens_mistral': 729, 'n_tokens_neox': 697, 'n_words': 205}