Skip to content

Instantly share code, notes, and snippets.

@jasondown
Last active July 16, 2021 00:37
Show Gist options
  • Save jasondown/c0aa88b4d45244faa0bce3a08b167f70 to your computer and use it in GitHub Desktop.
Save jasondown/c0aa88b4d45244faa0bce3a08b167f70 to your computer and use it in GitHub Desktop.
Combining Partial Active Patterns 1
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