How do I deal with IEnumerable in F#?

f#

Solution

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")

Problem

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#?

Original source