diff --git a/src/FSharpPlus/Control/Collection.fs b/src/FSharpPlus/Control/Collection.fs index b541125b7..a653c5bc2 100644 --- a/src/FSharpPlus/Control/Collection.fs +++ b/src/FSharpPlus/Control/Collection.fs @@ -301,6 +301,7 @@ type DistinctBy = type GroupBy = static member GroupBy (x: Id<'T> , f: 'T->'Key, _: Id<'Key*Id<'T>> , []_impl: GroupBy) = let a = Id.run x in Id.create (f a, x) + static member GroupBy (x: Id2<'T> , f: 'T->'Key, _: Id2<'Key*Id2<'T>> , []_impl: GroupBy) = let a = Id2.run x in Id2.create (f a, x) static member GroupBy (x: seq<'T> , f: 'T->'Key, _: seq<'Key*seq<'T>> , []_impl: GroupBy) = Seq.groupBy f x static member GroupBy (x: list<'T>, f: 'T->'Key, _: list<'Key*list<'T>>, []_impl: GroupBy) = Seq.groupBy f x |> Seq.map (fun (x, y) -> x, Seq.toList y) |> Seq.toList static member GroupBy (x: 'T [] , f: 'T->'Key, _: ('Key*('T [])) [] , []_impl: GroupBy) = Seq.groupBy f x |> Seq.map (fun (x, y) -> x, Seq.toArray y) |> Seq.toArray diff --git a/src/FSharpPlus/Internals.fs b/src/FSharpPlus/Internals.fs index 37ca1448a..50676ec71 100644 --- a/src/FSharpPlus/Internals.fs +++ b/src/FSharpPlus/Internals.fs @@ -105,6 +105,16 @@ module Id = let map f (x: Id<_>) = Id (f x.getValue) let create x = Id x +type Id2<'t> (v: 't) = + let value = v + member _.getValue = value + +[] +module Id2 = + let run (x: Id2<_>) = x.getValue + let map f (x: Id2<_>) = Id2 (f x.getValue) + let create x = Id2 x + type Id0 (v: string) = let value = v member _.getValue = value diff --git a/tests/FSharpPlus.Tests/Collections.fs b/tests/FSharpPlus.Tests/Collections.fs index 8f985cd81..b3da89094 100644 --- a/tests/FSharpPlus.Tests/Collections.fs +++ b/tests/FSharpPlus.Tests/Collections.fs @@ -291,3 +291,10 @@ module Collections = let m = choose Some ((ofSeq :seq<_*_> -> Map<_,_>) (seq ["a", 1; "b", 2])) Assert.IsInstanceOf>> (Some m) + + // Compile tests + + let inline mapOfGroup (key: 'T -> 'Key when 'Key : equality) (sequence: '``Collection<'T>``) : Map<'Key, '``Collection<'T>``> = + sequence + |> groupBy key + |> Map.ofSeq