<commit_before>package thx.promise;

import haxe.ds.Option;
using thx.core.Arrays;
import thx.core.Error;
import thx.core.Nil;
using thx.core.Options;
import thx.core.Tuple;

class Future<T> {
  public static function afterAll(arr : Array<Future<Dynamic>>) : Future<Nil>
    return Future.create(function(callback)
      all(arr).then(function(_) callback(Nil.nil)));

  public static function all<T>(arr : Array<Future<T>>) : Future<Array<T>>
    return Future.create(function(callback) {
      var results = [],
          counter = 0;
      arr.mapi(function(p, i) {<commit_msg>added Future.sequence()<commit_after>package thx.promise;

import haxe.ds.Option;
using thx.core.Arrays;
import thx.core.Error;
import thx.core.Nil;
using thx.core.Options;
import thx.core.Tuple;

class Future<T> {
  public static function sequence(arr : Array<Future<Dynamic>>) : Future<Nil>
    return Future.create(function(callback : Dynamic -> Void) {
        function poll(_ : Dynamic) {
          if(arr.length == 0) {
            callback(nil);
          } else {
            arr.shift().then(poll);
          }
        }
        poll(null);
      });

  public static function afterAll(arr : Array<Future<Dynamic>>) : Future<Nil>
    return Future.create(function(callback)
      all(arr).then(function(_) callback(Nil.nil)));

  public static function all<T>(arr : Array<Future<T>>) : Future<Array<T>>
    return Future.create(function(callback) {
      var results = [],
          counter = 0;
      arr.mapi(function(p, i) {
{'fraction_non_alphanumeric': 0.14313984168865435, 'fraction_numerical': 0.001978891820580475, 'mean_word_length': 3.309659090909091, 'pattern_counts': {'":': 0, '<': 24, '<?xml version=': 0, '>': 25, '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': '7026771', 'n_tokens_mistral': 491, 'n_tokens_neox': 481, 'n_words': 100}