FSharpPlus icon indicating copy to clipboard operation
FSharpPlus copied to clipboard

toSeq defaults

Open gusty opened this issue 4 years ago • 2 comments

ToSeq Invokable has an overload for IEnumerable which has lower priority than the custom implementation (ToSeq explicitly defined on the type).

This cause some inconsistencies, in dictionary like types where toSeq doesn't give back the same as [type].toSeq.

However fixing this is technically a breaking change, we might have to wait for v2

gusty avatar Jun 04 '21 05:06 gusty

It worth noting that toList and toArray don't have this problem as there the IEnumerable overload has the least priority.

I'm not sure, what was the reason toSeq was done like that, maybe was just a distraction or could be a design decision.

gusty avatar Jun 04 '21 05:06 gusty

Still:

> Map.ofList [1, 'a'; 3, 'b']  |> Map.toList  ;;
val it : (int * char) list = [(1, 'a'); (3, 'b')]

> Map.ofList [1, 'a'; 3, 'b'] |> toList  ;;
val it : System.Collections.Generic.KeyValuePair<int,char> list =
  [[1, a] {Key = 1;
           Value = 'a';}; [3, b] {Key = 3;
                                  Value = 'b';}]

This is because Map is a built-in type and there is no specific overload to handle it, so it defaults to the IEnumerable one.

This should also be fixed as part of this issue.

gusty avatar Jun 04 '21 06:06 gusty