Skip to content

Instantly share code, notes, and snippets.

@Szer
Created July 11, 2018 12:15
Show Gist options
  • Select an option

  • Save Szer/a1c0d27acc8da9238a8a8284086b8ba2 to your computer and use it in GitHub Desktop.

Select an option

Save Szer/a1c0d27acc8da9238a8a8284086b8ba2 to your computer and use it in GitHub Desktop.
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