<commit_before>//
//  ComposedOperation.swift
//  Operations
//
//  Created by <NAME> on 28/08/2015.
//  Copyright © 2015 <NAME>. All rights reserved.
//

import Foundation

public class ComposedOperation<T: NSOperation>: Operation, OperationDidFinishObserver {

    public let operation: T
    public let target: Operation

    public required init(operation op: T) {
        target = op as? Operation ?? GroupOperation(operations: [op])
        operation = op
        super.init()
        name = "Composed Operation<\(operation.dynamicType)>"
        target.addObserver(self)
    }

    public override func cancel() {
        operation.cancel()
        super.cancel()
    }

    public override func execute() {
        produceOperation(target)
    }

    public func operationDidFinish(operation: Operation, errors: [ErrorType]) {
        if operation == target {
            finish(errors)
        }
    }
}

<commit_msg>[OPR-165]: Uses a creator block<commit_after>//
//  ComposedOperation.swift
//  Operations
//
//  Created by <NAME> on 28/08/2015.
//  Copyright © 2015 <NAME>. All rights reserved.
//

import Foundation

public class ComposedOperation<T: NSOperation>: Operation, OperationDidFinishObserver {

    public let target: Operation
    public var creator: () -> T    
    public var operation: T

    public required init(@autoclosure(escaping) operation _creator: () -> T) {
        let op = _creator()
        creator = _creator
        target = op as? Operation ?? GroupOperation(operations: [op])
        operation = op
        super.init()
        name = "Composed Operation"
        target.addObserver(self)
    }

    public override func cancel() {
        operation.cancel()
        super.cancel()
    }

    public override func execute() {
        produceOperation(target)
    }

    public func operationDidFinish(operation: Operation, errors: [ErrorType]) {
        if operation == target {
            finish(errors)
        }
    }
}


{'fraction_non_alphanumeric': 0.1065989847715736, 'fraction_numerical': 0.013705583756345178, 'mean_word_length': 2.445804195804196, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 12, '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': '2355968', 'n_tokens_mistral': 565, 'n_tokens_neox': 527, 'n_words': 154}