Last active
June 7, 2017 18:15
-
-
Save jamessdixon/5a27cce3c1ab0b66386b81a156a7f69a to your computer and use it in GitHub Desktop.
ROP Example
This file contains 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
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="[email protected]"} | |
let customerInput = Good customer | |
validateRequest customerInput |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment