Created
June 28, 2014 16:44
-
-
Save sebfia/d386cadc036113616661 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
let (|Int|_|) str = | |
match Int32.TryParse(str) with | |
| (true,int) -> Some int | |
| _ -> None | |
let (|Bool|_|) str = | |
match Boolean.TryParse(str) with | |
| (true,bool) -> Some bool | |
| _ -> None | |
let (|DeNull|_|) arg = | |
match arg with | |
| null -> None | |
| a -> Some a | |
let (|Date|_|) str = | |
match DateTime.TryParse(str) with | |
| (true,date) -> Some date | |
| _ -> None | |
let whatAmI = | |
function | |
| DeNull str -> | |
match str with | |
| Int _ -> printfn "I'm an Int" | |
| Bool _ -> printfn "I'm a Bool" | |
| Date _ -> printfn "I'm a DateTime" | |
| _ -> printfn "I'm something which I don't know, but definitely no dumb null" | |
| _ -> printfn "I'm a dumb null from another planet" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
That's what I love F# and ActivePatterns for:
It makes my code readable and succinct.