Created
July 11, 2018 12:15
-
-
Save Szer/a1c0d27acc8da9238a8a8284086b8ba2 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
| open FSharpx.Option | |
| module String20 = | |
| open System.Text.RegularExpressions | |
| type T = String20 of string | |
| let createWithCont success failure (s: string) = | |
| if Regex.IsMatch(s,@"^\w{1,20}$") | |
| then success (String20 s) | |
| else failure "string length is more than 20" | |
| let create = | |
| createWithCont Some (fun _ -> None) | |
| module Player = | |
| type T = | |
| { NickName : String20.T | |
| FirstName : String20.T } | |
| let create nickName firstName = maybe { | |
| let! nick = String20.create nickName | |
| let! fn = String20.create firstName | |
| return | |
| { NickName = nick | |
| FirstName = fn } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment