Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
Create a seq.toIList extension #785
Create a seq.toIList extension
I propose we add a simple extension to the library to convert from a collection to an IList, to make life easier when using certain APIs
It could implement something like:
open System.Linq open System.Collections.Generic module Seq = let toIList(dataIn:seq<'T>):List<'T> = dataIn.ToList()
used like, for example in a .NET Google API:
let request = service.UserRoles.List(userProfileId) request.Ids <- Repeatable(userRoleList |> List.map (fun x -> x.ToString()) |> Seq.toIList) request.execute()
where "Repeatable" expects a Collections.Generic.IEnumerable.
The existing way of approaching this problem in F# is to use a method like ResizeArray or to open System.Linq and System.Collections.Generic in the module, which seems like overkill.
Pros and Cons
The advantages of making this adjustment to F# are:
The disadvantages of making this adjustment to F# are:
Estimated cost (XS, S, M, L, XL, XXL):
Affidavit (please submit!)
Please tick this by placing a cross in the box:
Please tick all that apply:
Yes, I found out about ResizeArray when I asked a friend on Twitter. I just think it's quite non-obvious as the solution to this problem. When the API requires something that satisfies IList, it's not immediately apparent that ResizeArray is the answer. And neither the compiler nor the intellisense are much help in figuring out the answer.
My perspective is as someone who uses F# without having had a grounding in the wider .NET ecosystem, so I don't have an intuitive understanding of the different interfaces (which is my failing, to an extent). There's already a slight eyebrow raise when you first learn that an F# list is not the same as a .NET list, but when the available methods to convert between them when you need to are non-obvious, or hidden in System.Linq, or whatever, it doesn't help on the usability front. And you need to know a little bit of background in order to make a sensible search on StackOverflow.
If System.Collections.Generic.List is wanted you can use constructor of it directly. No ResizeArray alias type is need to know nor C#ish System.Linq .ToList() is required. And if IList is wanted you can currently use seq.toArray too.
If you don't have C# background and you are using C# API with F# it can have it weirdness (almost by definition) but I think this won't improve things much.
I think that default flow of thought should be something like: interface is wanted but type you have is not implementing that. Find implementation candidate and see how it can be constructed. Instead of looking your original source object/module for .To# methods/functions. With all sympathy.