Skip to content

Commit b237216

Browse files
authored
Fix internal Id type being selected in overload resolution (#633)
1 parent ba1d4ff commit b237216

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

src/FSharpPlus/Control/Collection.fs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,7 @@ type DistinctBy =
301301

302302
type GroupBy =
303303
static member GroupBy (x: Id<'T> , f: 'T->'Key, _: Id<'Key*Id<'T>> , [<Optional>]_impl: GroupBy) = let a = Id.run x in Id.create (f a, x)
304+
static member GroupBy (x: Id2<'T> , f: 'T->'Key, _: Id2<'Key*Id2<'T>> , [<Optional>]_impl: GroupBy) = let a = Id2.run x in Id2.create (f a, x)
304305
static member GroupBy (x: seq<'T> , f: 'T->'Key, _: seq<'Key*seq<'T>> , [<Optional>]_impl: GroupBy) = Seq.groupBy f x
305306
static member GroupBy (x: list<'T>, f: 'T->'Key, _: list<'Key*list<'T>>, [<Optional>]_impl: GroupBy) = Seq.groupBy f x |> Seq.map (fun (x, y) -> x, Seq.toList y) |> Seq.toList
306307
static member GroupBy (x: 'T [] , f: 'T->'Key, _: ('Key*('T [])) [] , [<Optional>]_impl: GroupBy) = Seq.groupBy f x |> Seq.map (fun (x, y) -> x, Seq.toArray y) |> Seq.toArray

src/FSharpPlus/Internals.fs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,16 @@ module Id =
105105
let map f (x: Id<_>) = Id (f x.getValue)
106106
let create x = Id x
107107

108+
type Id2<'t> (v: 't) =
109+
let value = v
110+
member _.getValue = value
111+
112+
[<RequireQualifiedAccess>]
113+
module Id2 =
114+
let run (x: Id2<_>) = x.getValue
115+
let map f (x: Id2<_>) = Id2 (f x.getValue)
116+
let create x = Id2 x
117+
108118
type Id0 (v: string) =
109119
let value = v
110120
member _.getValue = value

tests/FSharpPlus.Tests/Collections.fs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,3 +291,10 @@ module Collections =
291291

292292
let m = choose Some ((ofSeq :seq<_*_> -> Map<_,_>) (seq ["a", 1; "b", 2]))
293293
Assert.IsInstanceOf<Option<Map<string,int>>> (Some m)
294+
295+
// Compile tests
296+
297+
let inline mapOfGroup (key: 'T -> 'Key when 'Key : equality) (sequence: '``Collection<'T>``) : Map<'Key, '``Collection<'T>``> =
298+
sequence
299+
|> groupBy key
300+
|> Map.ofSeq

0 commit comments

Comments
 (0)