Skip to content

Instantly share code, notes, and snippets.

@AngelMunoz
Last active July 31, 2021 16:03
Show Gist options
  • Save AngelMunoz/dcc4a909a1b08c2060e802e9c187c140 to your computer and use it in GitHub Desktop.
Save AngelMunoz/dcc4a909a1b08c2060e802e9c187c140 to your computer and use it in GitHub Desktop.
open System.IO
// each case is kind of a "label"
// active patterns are limited to 7 choices though so keep that in mind
let (|IsNet50|Else|EndsWithSlash|) (path: string) =
if path.EndsWith("net5.0") then
IsNet50
else if path.EndsWith('/')then
EndsWithSlash
else Else path
let basePath =
// use the pattern matching against a string
let path = Path.GetFullPath "."
match path with
| IsNet50 -> Path.GetFullPath "../../../"
| EndsWithSlash -> path.[.. path.Length - 1]
| Else path -> path
// if you wanted to add more cases, you would need to add more labels to the active pattern
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment