Skip to content

Instantly share code, notes, and snippets.

@talesin
Created April 22, 2026 23:15
Show Gist options
  • Select an option

  • Save talesin/c66302ea9fb145bfb13145542eee65a8 to your computer and use it in GitHub Desktop.

Select an option

Save talesin/c66302ea9fb145bfb13145542eee65a8 to your computer and use it in GitHub Desktop.
Generci tryParse for F#
/// TryParse utility for various types
let inline tryParse< ^a when ^a : (static member TryParse : string * byref< ^a> -> bool)> s : ^a option =
let mutable value = Unchecked.defaultof< ^a>
if (^a : (static member TryParse : string * byref< ^a> -> bool) (s, &value)) then Some value
else None
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment