Created
June 1, 2022 14:54
-
-
Save davidglassborow/7da045c580a6917863c632be550b968c to your computer and use it in GitHub Desktop.
Alternate version of Private DU constructor
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
// http://www.fssnip.net/ma/title/Alternate-version-of-Private-DU-constructor | |
module Email = | |
type EmailAddress = | |
private | |
| ValidEmail of string | |
| InvalidEmail of string | |
let ofString = function | |
| "validEmail" -> ValidEmail "validEmail" | |
| invalid -> InvalidEmail invalid | |
let (|ValidEmail|InvalidEmail|) = function | |
| ValidEmail email -> ValidEmail email | |
| InvalidEmail email -> InvalidEmail email | |
open Email | |
let invalid = Email.ofString "invalid" | |
let valid = Email.ofString "validEmail" | |
match invalid with | |
| InvalidEmail invalid -> printfn "invalid was InvalidEmail %s" invalid | |
| ValidEmail valid -> printfn "invalid was ValidEmail %s" valid | |
match valid with | |
| InvalidEmail invalid -> printfn "valid was InvalidEmail %s" invalid | |
| ValidEmail valid -> printfn "valid was ValidEmail %s" valid |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment