Skip to content

Commit

Permalink
+ DateOnly as Monoid and Zero for TimeOnly
Browse files Browse the repository at this point in the history
  • Loading branch information
gusty committed Sep 16, 2023
1 parent 1283d35 commit 41a935a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/FSharpPlus/Control/Monoid.fs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ type Plus =
static member ``+`` (x: array<_> , y , [<Optional>]_mthd: Plus ) = Array.append x y
static member ``+`` (() , () , [<Optional>]_mthd: Plus ) = ()
static member ``+`` (x: bool , y: bool , [<Optional>]_mthd: Plus ) = x <> y

#if NET6_0_OR_GREATER
static member ``+`` (x: DateOnly , y: DateOnly , [<Optional>]_mthd: Plus ) = DateOnly.FromDayNumber (x.DayNumber + y.DayNumber)
#endif

static member ``+`` (x: Set<_> , y , [<Optional>]_mthd: Plus ) = Set.union x y

#if !FABLE_COMPILER
Expand Down
6 changes: 6 additions & 0 deletions src/FSharpPlus/Control/Numeric.fs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ type FromInt32 =
static member FromInt32 (_: uint64 , _: FromInt32) = fun (x: int32) -> uint64 x
static member FromInt32 (_: float32 , _: FromInt32) = fun (x: int32) -> float32 x
static member FromInt32 (_: decimal , _: FromInt32) = fun (x: int32) -> decimal x

#if NET6_0_OR_GREATER
static member FromInt32 (_: System.DateOnly , _: FromInt32) = fun (x: int32) -> System.DateOnly.FromDayNumber x
#endif

static member inline Invoke (x: int32) : 'Num =
let inline call_2 (a: ^a, b: ^b) = ((^a or ^b) : (static member FromInt32 : _*_ -> _) b, a)
Expand Down Expand Up @@ -133,6 +137,8 @@ type Zero =
inherit Default1

static member Zero (_: System.TimeSpan , _: Zero ) = System.TimeSpan ()
static member Zero (_: System.DateOnly , _: Zero ) = System.DateOnly.MinValue
static member Zero (_: System.TimeOnly , _: Zero ) = System.TimeOnly.MinValue
static member Zero (_: DmStruct , _: Zero ) = Unchecked.defaultof<DmStruct>
static member Zero (_: list<'a> , _: Zero ) = [] : list<'a>
static member Zero (_: option<'a> , _: Zero ) = None : option<'a>
Expand Down

0 comments on commit 41a935a

Please sign in to comment.