Skip to content

Commit 97113eb

Browse files
authored
Merge pull request #86 from gusty/groupBy-cleanup
Cleanup groupBy logic
2 parents 870f7dd + f1afb7f commit 97113eb

1 file changed

Lines changed: 5 additions & 9 deletions

File tree

src/FSharp.Control.AsyncSeq/AsyncSeq.fs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ namespace FSharp.Control
66

77
open System
88
open System.Diagnostics
9-
open System.IO
109
open System.Collections.Generic
1110
open System.Threading
1211
open System.Threading.Tasks
@@ -1659,15 +1658,12 @@ module AsyncSeq =
16591658

16601659

16611660

1662-
type private Group<'k, 'a> = { key : 'k ; src : AsyncSeqSrc<'a> }
1663-
16641661
let groupByAsync (p:'a -> Async<'k>) (s:AsyncSeq<'a>) : AsyncSeq<'k * AsyncSeq<'a>> = asyncSeq {
1665-
let groups = Collections.Generic.Dictionary<'k, Group<'k, 'a>>()
1662+
let groups = Dictionary<'k, AsyncSeqSrc< 'a>>()
16661663
let close group =
1667-
groups.Remove(group.key) |> ignore
1668-
AsyncSeqSrcImpl.close group.src
1664+
AsyncSeqSrcImpl.close group
16691665
let closeGroups () =
1670-
groups.Values |> Seq.toArray |> Array.iter close
1666+
groups.Values |> Seq.iter close
16711667
use enum = s.GetEnumerator()
16721668
let rec go () = asyncSeq {
16731669
try
@@ -1678,13 +1674,13 @@ module AsyncSeq =
16781674
let! key = p a
16791675
let mutable group = Unchecked.defaultof<_>
16801676
if groups.TryGetValue(key, &group) then
1681-
AsyncSeqSrcImpl.put a group.src
1677+
AsyncSeqSrcImpl.put a group
16821678
yield! go ()
16831679
else
16841680
let src = AsyncSeqSrcImpl.create ()
16851681
let subSeq = src |> AsyncSeqSrcImpl.toAsyncSeq
16861682
AsyncSeqSrcImpl.put a src
1687-
let group = { key = key ; src = src }
1683+
let group = src
16881684
groups.Add(key, group)
16891685
yield key,subSeq
16901686
yield! go ()

0 commit comments

Comments
 (0)