Skip to content

Instantly share code, notes, and snippets.

@jamessdixon
Last active June 7, 2017 18:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jamessdixon/5a27cce3c1ab0b66386b81a156a7f69a to your computer and use it in GitHub Desktop.
Save jamessdixon/5a27cce3c1ab0b66386b81a156a7f69a to your computer and use it in GitHub Desktop.
ROP Example
type Customer = {Name:string; Email:string}
type Input = {Customer:Customer; MaxNameLength:int}
type Result<'t> =
| Good of 't
| Bad of string
let bind switchFunction =
fun twoTrackInput ->
match twoTrackInput with
| Good g -> switchFunction g
| Bad b -> Bad b
let (>>==) twoTrackInput switchFunction =
bind switchFunction twoTrackInput
let nameNotBlank input =
if input.Name = "" then Bad "Need Name"
else Good input
let nameMax maxAmount input =
if input.Name.Length > maxAmount then Bad "Too Long"
else Good input
let emailNotBlank input =
if input.Email = "" then Bad "Need Email"
else Good input
let validateRequest twoTrackInput =
twoTrackInput
>>== nameNotBlank
>>== nameMax 50
>>== emailNotBlank
let customer = {Name="Jamie";Email="jamie@aol.com"}
let customerInput = Good customer
validateRequest customerInput
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment