<commit_before>//
//  TaskCollections.swift
//  Deferred
//
//  Created by <NAME> on 11/18/15.
//  Copyright © 2015-2016 Big Nerd Ranch. Licensed under MIT.
//

#if SWIFT_PACKAGE
import Deferred
import Result
#endif

import Dispatch

// Deferred#124
#if os(macOS) || os(iOS) || os(tvOS) || os(watchOS)
import class Foundation.Progress

extension Collection where Iterator.Element: FutureProtocol, Iterator.Element.Value: Either, Iterator.Element.Value.Left == Error {
    /// Compose a number of tasks into a single notifier task.
    ///
    /// If any of the contained tasks fail, the returned task will be determined
    /// with that failure. Otherwise, once all operations succeed, the returned
    /// task will be determined a success.
    public func allSucceeded() -> Task<Void> {
        if isEmpty {
            return Task(success: ())
        }

        let coalescingDeferred = Deferred<Task<Void>.Result>()
        let outerProgress = Progress(parent: nil, userInfo: nil)
        outerProgress.totalUnitCount = numericCast(count)
        let group = DispatchGroup()
        let queue = DispatchQueue.global(qos: .utility)

        for task in self {
            let innerProgress = Progress.wrapped(task, cancellation: nil)
            outerProgress.adoptChild(innerProgress, orphaned: true, pendingUnitCount: 1)

            group.enter()
            task.upon(queue) { result in
                result.withValues(ifLeft: { (error) in<commit_msg>Fix typo leading to problems with allSucceeded progress tracking (#130)<commit_after>//
//  TaskCollections.swift
//  Deferred
//
//  Created by <NAME> on 11/18/15.
//  Copyright © 2015-2016 Big Nerd Ranch. Licensed under MIT.
//

#if SWIFT_PACKAGE
import Deferred
import Result
#endif

import Dispatch

// Deferred#124
#if os(macOS) || os(iOS) || os(tvOS) || os(watchOS)
import class Foundation.Progress

extension Collection where Iterator.Element: FutureProtocol, Iterator.Element.Value: Either, Iterator.Element.Value.Left == Error {
    /// Compose a number of tasks into a single notifier task.
    ///
    /// If any of the contained tasks fail, the returned task will be determined
    /// with that failure. Otherwise, once all operations succeed, the returned
    /// task will be determined a success.
    public func allSucceeded() -> Task<Void> {
        if isEmpty {
            return Task(success: ())
        }

        let coalescingDeferred = Deferred<Task<Void>.Result>()
        let outerProgress = Progress(parent: nil, userInfo: nil)
        outerProgress.totalUnitCount = numericCast(count)
        let group = DispatchGroup()
        let queue = DispatchQueue.global(qos: .utility)

        for task in self {
            let innerProgress = Progress.wrapped(task, cancellation: nil)
            outerProgress.adoptChild(innerProgress, orphaned: false, pendingUnitCount: 1)

            group.enter()
            task.upon(queue) { result in
                result.withValues(ifLeft: { (error) in
{'fraction_non_alphanumeric': 0.10157559503855179, 'fraction_numerical': 0.013074086490110626, 'mean_word_length': 2.748743718592965, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 13, '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': '4312800', 'n_tokens_mistral': 874, 'n_tokens_neox': 820, 'n_words': 268}