There are quite a few legacy interfaces that get collections of entities in form of plain IEnumerable
. Commonly one would do foreach(CertainTypeWeSureItemIs item in items)
in C# casting objects to whatever type they want as they go. IEnumerable doesn't translate directly to a sequence. Wrapping it in seq { for x in xs -> x }
doesn't help much either because it gets seq{obj}
. So how do I do this in F#?
Use Seq.cast<T>
:
let al = new System.Collections.ArrayList()
al.Add(1) |> ignore
al.Add(2) |> ignore
al |> Seq.cast<int> |> Seq.iter(printf "%i")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With