Skip to content

Instantly share code, notes, and snippets.

@kristopherjohnson
Last active August 29, 2015 14:00
Show Gist options
  • Save kristopherjohnson/3849f6b12854b020c7d2 to your computer and use it in GitHub Desktop.
Save kristopherjohnson/3849f6b12854b020c7d2 to your computer and use it in GitHub Desktop.
F# utility functions for Enum types
open System
module EnumUtil =
/// Return all values for an enumeration type
let EnumValues (enumType : Type) : seq<int> =
let values = Enum.GetValues enumType
let getValue (i : int) : int = downcast values.GetValue i
let lb = values.GetLowerBound 0
let ub = values.GetUpperBound 0
seq { lb .. ub } |> Seq.map getValue
/// Return minimum and maximum values for an enumeration type
let EnumValueRange (enumType : Type) : int * int =
let values = EnumValues enumType |> Seq.toList
(List.min values), (List.max values)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment