Last active
July 16, 2021 00:37
-
-
Save jasondown/c0aa88b4d45244faa0bce3a08b167f70 to your computer and use it in GitHub Desktop.
Combining Partial Active Patterns 1
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 | |
open System.Globalization | |
type LogMessage = | |
| Info of DateTime * Message : string | |
| Warning of DateTime * Message : string | |
| Error of DateTime * Code : int * Message : string | |
let (|Date|_|) (input : string) = | |
let success, date = | |
DateTime.TryParseExact(input, [|"dd/MM/yyyy HH:mm:ss"|], CultureInfo.InvariantCulture, DateTimeStyles.None) | |
if success then Some(date) else None | |
let (|Int|_|) (input : string) = | |
let success, int = Int32.TryParse input | |
if success then Some(int) else None |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment