Created
January 19, 2021 14:29
-
-
Save isaacabraham/bc945ade32911f27d80b237657b58d8c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /// An example union. | |
| type Team = Tottenham | Spurs | THFC | |
| module Lists = | |
| open FSharp.Reflection | |
| /// Creates an array of all cases of a given union 'T. | |
| let makeAll<'T> = | |
| FSharpType.GetUnionCases typeof<'T> | |
| |> Array.map(fun info -> FSharpValue.MakeUnion(info, Array.empty) :?> 'T) | |
| /// All Team cases - calculated once | |
| let Teams = makeAll<Team> | |
| type Team with | |
| /// For added ease of use, you could add this static extension member onto Team | |
| static member All = Lists.Teams | |
| let allTeams = Lists.Teams | |
| let allTeamsAgain = Team.All |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment