<commit_before>//
//  ExistentialTask.swift
//  Deferred
//
//  Created by <NAME> on 3/28/16.
//  Copyright © 2015-2016 <NAME>. Licensed under MIT.
//

#if SWIFT_PACKAGE
import Deferred
import Result
#endif

import Dispatch

/// A wrapper over any task.
///
/// Forwards operations to an arbitrary underlying future having the same result
/// type, optionally combined with some `cancellation`.
#if os(macOS) || os(iOS) || os(tvOS) || os(watchOS)
import class Foundation.Progress
import protocol Foundation.ProgressReporting

public final class Task<SuccessValue>: NSObject, ProgressReporting {
    public typealias Result = TaskResult<SuccessValue>

    fileprivate let future: Future<Result>
    public let progress: Progress

    /// Creates a task given a `future` and its `progress`.
    public init(future: Future<Result>, progress: Progress) {
        self.future = future
        self.progress = .taskRoot(for: progress)
    }

    /// Create a task that will never complete.
    public override init() {
        self.future = Future()
        self.progress = .indefinite()
    }

    /// Creates a task whose `upon(_:execute:)` methods use the result of `base`.
    public convenience init<Task: FutureProtocol>(_ base: Task, progress: Progress)
        where Task.Value: Either, Task.Value.Left == Error, Task.Value.Right == SuccessValue {
        self.init(future: Future(task: base), progress: progress)
    }

    /// Creates a task given a `future` and an optional `cancellation`.
    ///
    /// If `base` is not a `Task`, `cancellation` will be called asynchronously,
    /// but not on any specific queue. If you must do work on a specific queue,
    /// schedule work on it.
    public convenience init(future base: Future<Result>, cancellation: ((Void) -> Void)? = nil) {
        let progress = Progress.wrapped(base, cancellation: cancellation)
        self.init(future: base, progress: progress)
    }

    /// Creates a task whose `upon(_:execute:)` methods use the result of `base`.
    ///
    /// If `base` is not a `Task`, `cancellation` will be called asynchronously,
    /// but not on any specific queue. If you must do work on a specific queue,
    /// schedule work on it.
    public convenience init<Task: FutureProtocol>(_ base: Task, cancellation: ((Void) -> Void)? = nil)
        where Task.Value: Either, Task.Value.Left == Error, Task.Value.Right == SuccessValue {
        let progress = Progress.wrapped(base, cancellation: cancellation)
        self.init(future: Future(task: base), progress: progress)
    }
}
#else
public final class Task<SuccessValue> {
    public typealias Result = TaskResult<SuccessValue>

    fileprivate let future: Future<Result>
    public let cancellation: (() -> Void)

    /// Creates a task given a `future` and an optional `cancellation`.
    ///
    /// If `base` is not a `Task`, `cancellation` will be called asynchronously,
    /// but not on any specific queue. If you must do work on a specific queue,
    /// schedule work on it.
    public init(future: Future<Result>, cancellation: ((Void) -> Void)? = nil) {
        self.future = future
        self.cancellation = cancellation ?? {}
    }

    /// Create a task that will never complete.
    public init() {
        self.future = Future()
        self.cancellation = {}
    }

    private typealias _Self = Task<SuccessValue>

    /// Creates a task whose `upon(_:execute:)` methods use the result of `base`.
    ///
    /// If `base` is not a `Task`, `cancellation` will be called asynchronously,
    /// but not on any specific queue. If you must do work on a specific queue,
    /// schedule work on it.
    public convenience init<Task: FutureProtocol>(_ base: Task, cancellation: ((Void) -> Void)? = nil)
        where Task.Value: Either, Task.Value.Left == Error, Task.Value.Right == SuccessValue {
        self.init(future: Future(task: base), cancellation: (base as? _Self)?.cancellation ?? cancellation)
    }
}
#endif

extension Task: FutureProtocol {
    public typealias Value = Result
    public typealias PreferredExecutor = Future<Result>.PreferredExecutor

    public func upon(_ queue: PreferredExecutor, execute body: @escaping(Result) -> ()) {
        future.upon(queue, execute: body)
    }

    public func upon(_ executor: Executor, execute body: @escaping(Result) -> ()) {<commit_msg>Shuffle around Task implementation to make Jazzy happy<commit_after>//
//  ExistentialTask.swift
//  Deferred
//
//  Created by <NAME> on 3/28/16.
//  Copyright © 2015-2016 <NAME>. Licensed under MIT.
//

#if SWIFT_PACKAGE
import Deferred
import Result
#endif

import Dispatch
import class Foundation.NSObject
#if os(macOS) || os(iOS) || os(tvOS) || os(watchOS)
import class Foundation.Progress
import protocol Foundation.ProgressReporting
#endif

/// A wrapper over any task.
///
/// Forwards operations to an arbitrary underlying future having the same result
/// type, optionally combined with some `cancellation`.
public final class Task<SuccessValue>: NSObject {
    public typealias Result = TaskResult<SuccessValue>

    fileprivate let future: Future<Result>

    #if os(macOS) || os(iOS) || os(tvOS) || os(watchOS)
    public let progress: Progress

    /// Creates a task given a `future` and its `progress`.
    public init(future: Future<Result>, progress: Progress) {
        self.future = future
        self.progress = .taskRoot(for: progress)
    }

    /// Creates a task given a `future` and an optional `cancellation`.
    ///
    /// If `base` is not a `Task`, `cancellation` will be called asynchronously,
    /// but not on any specific queue. If you must do work on a specific queue,
    /// schedule work on it.
    public convenience init(future base: Future<Result>, cancellation: ((Void) -> Void)? = nil) {
        let progress = Progress.wrapped(base, cancellation: cancellation)
        self.init(future: base, progress: progress)
    }

    /// Creates a task whose `upon(_:execute:)` methods use the result of `base`.
    public convenience init<Task: FutureProtocol>(_ base: Task, progress: Progress)
        where Task.Value: Either, Task.Value.Left == Error, Task.Value.Right == SuccessValue {
        self.init(future: Future(task: base), progress: progress)
    }
    #else
    internal let cancellation: (() -> Void)

    /// Creates a task given a `future` and an optional `cancellation`.
    ///
    /// If `base` is not a `Task`, `cancellation` will be called asynchronously,
    /// but not on any specific queue. If you must do work on a specific queue,
    /// schedule work on it.
    public init(future: Future<Result>, cancellation: ((Void) -> Void)? = nil) {
        self.future = future
        self.cancellation = cancellation ?? {}
    }
    #endif

    /// Create a task that will never complete.
    public override init() {
        self.future = Future()
        #if os(macOS) || os(iOS) || os(tvOS) || os(watchOS)
        self.progress = .indefinite()
        #else
        self.cancellation = {}
        #endif
    }

    private typealias _Self = Task<SuccessValue>

    /// Creates a task whose `upon(_:execute:)` methods use the result of `base`.
    ///
    /// If `base` is not a `Task`, `cancellation` will be called asynchronously,
    /// but not on any specific queue. If you must do work on a specific queue,
    /// schedule work on it.
    public convenience init<Task: FutureProtocol>(_ base: Task, cancellation: ((Void) -> Void)? = nil)
        where Task.Value: Either, Task.Value.Left == Error, Task.Value.Right == SuccessValue {
        #if os(macOS) || os(iOS) || os(tvOS) || os(watchOS)
        let progress = Progress.wrapped(base, cancellation: cancellation)
        self.init(future: Future(task: base), progress: progress)
        #else
        self.init(future: Future(task: base), cancellation: (base as? _Self)?.cancellation ?? cancellation)
        #endif
    }

}

extension Task: FutureProtocol {
    public typealias Value = Result
    public typealias PreferredExecutor = Future<Result>.PreferredExecutor

    public func upon(_ queue: PreferredExecutor, execute body: @escaping(Result) -> ()) {
        future.upon(queue, execute: body)
    }

    public func upon(_ executor: Executor, execute body: @escaping(Result) -> ()) {
{'fraction_non_alphanumeric': 0.12080455591905974, 'fraction_numerical': 0.003150369562583303, 'mean_word_length': 2.9759152215799616, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 44, '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': '107674', 'n_tokens_mistral': 2349, 'n_tokens_neox': 2268, 'n_words': 840}