<commit_before>/**
 This general `when` is not the most useful since everything becomes
 `AnyObject`. Swift generics are not ready for arbituary numbers of
 varying generic types, so this is the best you get if you have more
 than two things you need to `when` currently.
*/
public func when(promises: Promise<AnyObject>...) -> Promise<[AnyObject]> {
    if promises.isEmpty {
        return Promise<[AnyObject]>(value:[])
    }

    let (promise, fulfiller, rejecter) = Promise<[AnyObject]>.defer()
    var results = Array<AnyObject>(count: promises.count, repeatedValue: NSNull())
    var x = 0
    for (index, promise) in enumerate(promises) {
        promise.then{ (value) -> Void in
            results[index] = value
            if ++x == promises.count {
                fulfiller(results)
            }
        }
        promise.catch(rejecter)
    }

    return promise
}

public func when<U,V>(promise1: Promise<U>, promise2: Promise<V>) -> Promise<(U,V)> {
    let (promise, fulfiller, rejecter) = Promise<(U,V)>.defer()
    var first:Any?
    promise1.then{ u->() in
        if let seal = first {
            let fulfillment = (u, seal as V)
            fulfiller(fulfillment)
        } else {
            first = u
        }
    }
    promise2.then{ v->() in
        if let seal = first {
            let fulfillment = (seal as U, v)
            fulfiller(fulfillment)
        } else {
            first = v<commit_msg>Add a form of when that takes an array<commit_after>/**
 This general `when` is not the most useful since everything becomes
 `AnyObject`. Swift generics are not ready for arbituary numbers of
 varying generic types, so this is the best you get if you have more
 than two things you need to `when` currently.
*/
public func when(promises: [Promise<AnyObject>]) -> Promise<[AnyObject]> {
    if promises.isEmpty {
        return Promise<[AnyObject]>(value:[])
    }

    let (promise, fulfiller, rejecter) = Promise<[AnyObject]>.defer()
    var results = Array<AnyObject>(count: promises.count, repeatedValue: NSNull())
    var x = 0
    for (index, promise) in enumerate(promises) {
        promise.then{ (value) -> Void in
            results[index] = value
            if ++x == promises.count {
                fulfiller(results)
            }
        }
        promise.catch(rejecter)
    }

    return promise
}

public func when(promises: Promise<AnyObject>...) -> Promise<[AnyObject]> {
    return when(promises)
}

public func when<U,V>(promise1: Promise<U>, promise2: Promise<V>) -> Promise<(U,V)> {
    let (promise, fulfiller, rejecter) = Promise<(U,V)>.defer()
    var first:Any?
    promise1.then{ u->() in
        if let seal = first {
            let fulfillment = (u, seal as V)
            fulfiller(fulfillment)
        } else {
            first = u
        }
    }
    promise2.then{ v->() in
        if let seal = first {
            let fulfillment = (seal as U, v)
            fulfiller(fulfillment)
        } else {
            first = v
{'fraction_non_alphanumeric': 0.11861009021049114, 'fraction_numerical': 0.003341129301703976, 'mean_word_length': 2.293729372937294, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 36, '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': '1041190', 'n_tokens_mistral': 892, 'n_tokens_neox': 886, 'n_words': 280}