Skip to content

+ DateOnly and TimeOnly as Monoid #550

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
+ DateOnly as Monoid and Zero for TimeOnly
  • Loading branch information
gusty committed Sep 16, 2023
commit 41a935af12a0e0b5f3e50649d5119d0691223445
5 changes: 5 additions & 0 deletions src/FSharpPlus/Control/Monoid.fs
Original file line number Diff line number Diff line change
@@ -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
6 changes: 6 additions & 0 deletions src/FSharpPlus/Control/Numeric.fs
Original file line number Diff line number Diff line change
@@ -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)
@@ -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>