Skip to content

Instantly share code, notes, and snippets.

@andrevdm
Last active August 29, 2015 14:21
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 andrevdm/164e87ec5609cf4eb7ba to your computer and use it in GitHub Desktop.
Save andrevdm/164e87ec5609cf4eb7ba to your computer and use it in GitHub Desktop.
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