<commit_before>namespace FSharp.Polyfill

open System.Threading

/// Extensions for async workflows.
[<AutoOpen>]
module AsyncExtensions = 
  open System
  open System.Threading.Tasks

  type Microsoft.FSharp.Control.Async with 
     /// Runs both computations in parallel and returns the result as a tuple.
    static member Parallel (a : Async<'a>, b : Async<'b>) : Async<'a * 'b> =
        async {
            let! a' = Async.StartChild a
            let! b' = Async.StartChild b
            let! a'' = a'
            let! b'' = b'
            return (a'',b'')
        }
    static member map f a =
        async { return f a }
    static member tryFind (f : 'T -> bool) (tasks : Async<'T> seq) = async {
         match Seq.toArray tasks with
         | [||] -> return [||], None
         | [|t|] ->
            let! res = t
            let task = Task.FromResult res
            return if f res then [|task|], None else [|task|], Some 0
         | tasks ->
    
         let! t = Async.CancellationToken
         return! Async.FromContinuations <|
             fun (sc,ec,cc) ->
                 let currentIndex = ref 0
                 let exnCount = ref 0
                 let innerCts = CancellationTokenSource.CreateLinkedTokenSource t
                 let results = Array.init tasks.Length (fun _ -> TaskCompletionSource<'T>())<commit_msg>fix Async.tryFind in special case of single item.<commit_after>namespace FSharp.Polyfill

open System.Threading

/// Extensions for async workflows.
[<AutoOpen>]
module AsyncExtensions = 
  open System
  open System.Threading.Tasks

  type Microsoft.FSharp.Control.Async with 
     /// Runs both computations in parallel and returns the result as a tuple.
    static member Parallel (a : Async<'a>, b : Async<'b>) : Async<'a * 'b> =
        async {
            let! a' = Async.StartChild a
            let! b' = Async.StartChild b
            let! a'' = a'
            let! b'' = b'
            return (a'',b'')
        }
    static member map f a =
        async { return f a }
    static member tryFind (f : 'T -> bool) (tasks : Async<'T> seq) = async {
         match Seq.toArray tasks with
         | [||] -> return [||], None
         | [|t|] ->
            let! res = t
            let task = Task.FromResult res
            return if f res then [|task|], Some 0 else [|task|], None
         | tasks ->
    
         let! t = Async.CancellationToken
         return! Async.FromContinuations <|
             fun (sc,ec,cc) ->
                 let currentIndex = ref 0
                 let exnCount = ref 0
                 let innerCts = CancellationTokenSource.CreateLinkedTokenSource t
                 let results = Array.init tasks.Length (fun _ -> TaskCompletionSource<'T>())
{'fraction_non_alphanumeric': 0.11119239209948793, 'fraction_numerical': 0.0021945866861741038, 'mean_word_length': 1.796523517382413, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 27, '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': '2111202', 'n_tokens_mistral': 779, 'n_tokens_neox': 780, 'n_words': 258}