5 people like it.

single-case DU with shadowed constructor

single-case DU with shadowed constructor for passing non-primitives around that are already validated.

1: 
2: 
3: 
4: 
5: 
6: 
7: 
8: 
type DoB = | DoB of DateTime

let DoB (dt:DateTime) = // shadow constructor
  if(dt.Year>1900) //what does the business say a min valid dob should be? 
  then Some(DoB dt) 
  else None

let dob= DoB(DateTime(2014,1,1))
Multiple items
union case DoB.DoB: obj -> DoB

--------------------
type DoB = | DoB of obj

Full name: Script.DoB
Multiple items
val DoB : dt:'a -> DoB option

Full name: Script.DoB

--------------------
type DoB = | DoB of obj

Full name: Script.DoB
val dt : 'a
union case Option.Some: Value: 'T -> Option<'T>
union case Option.None: Option<'T>
val dob : DoB option

Full name: Script.dob
Raw view Test code New version

More information

Link:http://fssnip.net/n9
Posted:10 years ago
Author:ImaginaryDevelopment.blogspot.com
Tags: discriminated union