Skip to content

Instantly share code, notes, and snippets.

@jasondown
Created January 20, 2017 19:30
Show Gist options
  • Select an option

  • Save jasondown/0e46303dd97e334666a489daa8e47583 to your computer and use it in GitHub Desktop.

Select an option

Save jasondown/0e46303dd97e334666a489daa8e47583 to your computer and use it in GitHub Desktop.
Multiple-Case Active Pattern, Decomposition 2
open System
let (|Spring|Summer|Fall|Winter|) (date : DateTime) =
match date.Month, date.Day with
| 1, d | 2, d | 3, d when d < 21 -> Winter
| 3, d | 4, d | 5, d | 6, d when d < 21 -> Spring
| 6, d | 7, d | 8, d | 9, d when d < 21 -> Summer
| 9, d | 10, d | 11, d | 12, d when d < 21 -> Fall
| _ -> Winter
@jasondown
Copy link
Author

NOTE: This has a subtle bug as discussed in this blog post (in the UPDATE: Aug-11-2020) section: http://www.jason-down.com/2017/01/24/f-pattern-matching-part-2-active-patterns/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment