Skip to content

Instantly share code, notes, and snippets.

@kos59125
Created September 25, 2012 06:03
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save kos59125/3780229 to your computer and use it in GitHub Desktop.
Enumerable.OfType in F#
let ofType<'a> (source : System.Collections.IEnumerable) : seq<'a> =
let resultType = typeof<'a>
seq {
for item in source do
match item with
| null -> ()
| _ ->
if resultType.IsAssignableFrom (item.GetType ())
then
yield (downcast item)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment