Sha256: 86c9b3d45d8c630cc4e9296df3d2ff6a53ddb0970608b4f7dd181aad6b3a9c62

Contents?: true

Size: 622 Bytes

Versions: 396

Compression:

Stored size: 622 Bytes

Contents

module ParallelLetterFrequency

open System

let merge x y = 
    let folder acc key value =
        match Map.tryFind key acc with
        | Some z -> Map.add key (z + value) acc
        | None -> Map.add key value acc
    Map.fold folder x y

let calculateFrequency text = 
    text
    |> Seq.filter (Char.IsLetter)
    |> Seq.countBy (fun c -> Char.ToLower c)
    |> Map.ofSeq

let asyncCalculateFrequency text = async { return calculateFrequency(text) }

let frequency texts = 
    texts
    |> Seq.map asyncCalculateFrequency   
    |> Async.Parallel
    |> Async.RunSynchronously 
    |> Seq.fold merge Map.empty

Version data entries

396 entries across 396 versions & 1 rubygems

Version Path
trackler-2.2.1.180 tracks/fsharp/exercises/parallel-letter-frequency/Example.fs
trackler-2.2.1.179 tracks/fsharp/exercises/parallel-letter-frequency/Example.fs
trackler-2.2.1.178 tracks/fsharp/exercises/parallel-letter-frequency/Example.fs
trackler-2.2.1.177 tracks/fsharp/exercises/parallel-letter-frequency/Example.fs
trackler-2.2.1.176 tracks/fsharp/exercises/parallel-letter-frequency/Example.fs
trackler-2.2.1.175 tracks/fsharp/exercises/parallel-letter-frequency/Example.fs
trackler-2.2.1.174 tracks/fsharp/exercises/parallel-letter-frequency/Example.fs
trackler-2.2.1.173 tracks/fsharp/exercises/parallel-letter-frequency/Example.fs
trackler-2.2.1.172 tracks/fsharp/exercises/parallel-letter-frequency/Example.fs
trackler-2.2.1.171 tracks/fsharp/exercises/parallel-letter-frequency/Example.fs
trackler-2.2.1.170 tracks/fsharp/exercises/parallel-letter-frequency/Example.fs
trackler-2.2.1.169 tracks/fsharp/exercises/parallel-letter-frequency/Example.fs
trackler-2.2.1.167 tracks/fsharp/exercises/parallel-letter-frequency/Example.fs
trackler-2.2.1.166 tracks/fsharp/exercises/parallel-letter-frequency/Example.fs
trackler-2.2.1.165 tracks/fsharp/exercises/parallel-letter-frequency/Example.fs
trackler-2.2.1.164 tracks/fsharp/exercises/parallel-letter-frequency/Example.fs
trackler-2.2.1.163 tracks/fsharp/exercises/parallel-letter-frequency/Example.fs
trackler-2.2.1.162 tracks/fsharp/exercises/parallel-letter-frequency/Example.fs
trackler-2.2.1.161 tracks/fsharp/exercises/parallel-letter-frequency/Example.fs
trackler-2.2.1.160 tracks/fsharp/exercises/parallel-letter-frequency/Example.fs