Last active
August 29, 2015 14:21
-
-
Save andrevdm/164e87ec5609cf4eb7ba to your computer and use it in GitHub Desktop.
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
open System | |
type PersonAge = PersonAge of int | |
type Person = { id: Guid; name: string; age: PersonAge} | |
let bjorn = { id=System.Guid.NewGuid(); name="Bjørn Einar"; age=PersonAge 34} | |
let changedName = {bjorn with name ="Bjørn the confused"} | |
let createAge age = | |
// somecrazybusiness rules with age and using services to check if the | |
// age is really correct and do all kinds of sideeffects | |
match age with | |
| i when i < 18 -> failwith "too young" | |
| i when i > 120 -> failwith "no you are not!" | |
| i -> PersonAge i | |
let changeAge (p:Person) (newAge:int) = | |
{p with age = (createAge newAge)} | |
let changedAgedBjorn = changeAge changedName 30 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment