Skip to content

Commit cd9ac3e

Browse files
committed
Merge remote-tracking branch 'origin/master' into gus/date-and-time
2 parents ee6c4c0 + 21f4a0b commit cd9ac3e

File tree

18 files changed

+343
-120
lines changed

18 files changed

+343
-120
lines changed

FSharpPlus.sln

Lines changed: 65 additions & 34 deletions
Large diffs are not rendered by default.

appveyor.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ install:
1616
build_script:
1717
- cmd: dotnet restore ./FSharpPlus.sln
1818
- cmd: dotnet build -c Release ./FSharpPlus.sln
19-
- cmd: dotnet test -c Release tests/FSharpPlus.Tests
19+
- cmd: dotnet test -c Test tests/FSharpPlus.Tests
2020
- ps: if ($env:VersionSuffix) { dotnet pack build.proj --version-suffix $env:VersionSuffix } else { dotnet pack build.proj }
2121
test: off
2222
artifacts:

build.proj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
<Target Name="Test">
1717
<Exec Command='dotnet build src/FSharpPlus.TypeLevel' WorkingDirectory="$(RepoRootDir)" IgnoreStandardErrorWarningFormat="true" />
18-
<Exec Command='dotnet test --blame-hang-timeout 30s tests/FSharpPlus.Tests -c Release --logger:trx' WorkingDirectory="$(RepoRootDir)" IgnoreStandardErrorWarningFormat="true" />
18+
<Exec Command='dotnet test --blame-hang-timeout 30s tests/FSharpPlus.Tests -c Test --logger:trx' WorkingDirectory="$(RepoRootDir)" IgnoreStandardErrorWarningFormat="true" />
1919
</Target>
2020

2121
<!-- dotnet msbuild -target:AllDocs build.proj -->

docsrc/content/abstraction-category.fsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ Minimal complete definition
2222
2323
*)
2424
(**
25-
static member get_Id() : 'Category<'T,'T>
26-
static member (<<<) (f:Category<'U,'V>, g:'Category<'T,'U>) : 'Category<'T,'V>
25+
static member get_Id() : 'Category<'T, 'T>
26+
static member (<<<) (f: 'Category<'U, 'V>, g: 'Category<'T, 'U>) : 'Category<'T, 'V>
2727
*)
2828
(**
2929
@@ -35,7 +35,7 @@ Other operations
3535
* ``(>>>)``
3636
*)
3737
(**
38-
static member (>>>) (g:'Category<'T,'U>, f:Category<'U,'V>) : 'Category<'T,'V>
38+
static member (>>>) (g: 'Category<'T, 'U>, f: 'Category<'U, 'V>) : 'Category<'T, 'V>
3939
*)
4040
(**
4141

docsrc/content/abstraction-comonad.fsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ Minimal complete definition
2323
2424
*)
2525
(**
26-
static member Extract (s:'Comonad<'T>) : 'T
27-
static member (=>>) (s:'Comonad<'T>, f:'Comonad<'T> -> 'U) : Comonad<'U>
26+
static member Extract (s: 'Comonad<'T>) : 'T
27+
static member (=>>) (s: 'Comonad<'T>, f: 'Comonad<'T> -> 'U) : 'Comonad<'U>
2828
*)
2929
(**
3030

docsrc/content/abstraction-monad.fsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ Minimal complete definition
2222
*)
2323
(**
2424
static member Return (x: 'T) : 'Monad<'T>
25-
static member (>>=) (x: Monad<'T>, f: 'T->Monad<'U>) : Monad<'U>
25+
static member (>>=) (x: 'Monad<'T>, f: 'T -> 'Monad<'U>) : 'Monad<'U>
2626
*)
2727
(**
2828
@@ -34,7 +34,7 @@ Other operations
3434
* ``join``
3535
*)
3636
(**
37-
static member Join (x:'Monad<'Monad<'T>>) :'Monad<'T>
37+
static member Join (x: 'Monad<'Monad<'T>>) : 'Monad<'T>
3838
*)
3939
(**
4040
@@ -361,4 +361,4 @@ Recommended reading
361361
362362
It contains examples using F#+ and an explanation from scratch.
363363
364-
*)
364+
*)

docsrc/content/abstraction-profunctor.fsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Minimal complete definition
2020
* ``dimap f g x``
2121
*)
2222
(**
23-
static member Dimap (x:'Profunctor<'T,'V>, f:'U->'T, g:'V->'W) :'Profunctor<'U,'W>
23+
static member Dimap (x: 'Profunctor<'T, 'V>, f: 'U -> 'T, g: 'V -> 'W) : 'Profunctor<'U, 'W>
2424
*)
2525
(**
2626
@@ -31,14 +31,14 @@ Other operations
3131
* ``lmap f x``
3232
*)
3333
(**
34-
static member Contramap (x:Profunctor<'T,'V>, f:'U->'T) :'Profunctor<'U,'V>
34+
static member Contramap (x: 'Profunctor<'T, 'V>, f: 'U -> 'T) : 'Profunctor<'U, 'V>
3535
*)
3636
(**
3737
3838
* ``rmap g x``
3939
*)
4040
(**
41-
static member Map (x:Profunctor<'T,'V>, f:'V->'W) :'Profunctor<'T,'W>
41+
static member Map (x: 'Profunctor<'T,'V>, f: 'V -> 'W) : 'Profunctor<'T, 'W>
4242
*)
4343
(**
4444

src/FSharpPlus.Docs/Samples/Learn You a Haskell.fsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -563,7 +563,7 @@ let loadedCoin = Prob [(Heads, 0.1); (Tails, 0.9)]
563563
// Prob [(false, 0.025); (false, 0.225); (false, 0.025); (false, 0.225);
564564
// (false, 0.025); (false, 0.225); (false, 0.025); (true, 0.225)]
565565
let flipThree : Prob<bool> =
566-
monad {
566+
monad' {
567567
let! a = coin
568568
let! b = coin
569569
let! c = loadedCoin

src/FSharpPlus/Control/Converter.fs

Lines changed: 81 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -111,26 +111,47 @@ type TryParse =
111111
static member TryParse (_: string , _: TryParse) = fun x -> Some x : option<string>
112112
static member TryParse (_: StringBuilder , _: TryParse) = fun x -> Some (new StringBuilder (x: string)) : option<StringBuilder>
113113
#if !FABLE_COMPILER
114-
static member TryParse (_: DateTime , _: TryParse) = fun (x:string) -> DateTime.TryParseExact (x, [|"yyyy-MM-ddTHH:mm:ss.fffZ"; "yyyy-MM-ddTHH:mm:ssZ"|], null, DateTimeStyles.RoundtripKind) |> tupleToOption : option<DateTime>
115-
static member TryParse (_: DateTimeOffset, _: TryParse) = fun (x:string) -> DateTimeOffset.TryParseExact (x, [|"yyyy-MM-ddTHH:mm:ss.fffK"; "yyyy-MM-ddTHH:mm:ssK"|], null, DateTimeStyles.RoundtripKind) |> tupleToOption : option<DateTimeOffset>
114+
115+
static member TryParse (_: DateTime , _: TryParse) = fun (x:string) ->
116+
match DateTime.TryParseExact (x, [|"yyyy-MM-ddTHH:mm:ss.fffZ"; "yyyy-MM-ddTHH:mm:ssZ"|], null, DateTimeStyles.RoundtripKind) with
117+
| true, x -> Some x
118+
| _ ->
119+
match DateTime.TryParse (x, CultureInfo.InvariantCulture, DateTimeStyles.None) with
120+
| true, x -> Some x
121+
| _ -> None
122+
123+
static member TryParse (_: DateTimeOffset, _: TryParse) = fun (x:string) ->
124+
match DateTimeOffset.TryParseExact (x, [|"yyyy-MM-ddTHH:mm:ss.fffK"; "yyyy-MM-ddTHH:mm:ssK"|], null, DateTimeStyles.AssumeUniversal) with
125+
| true, x -> Some x
126+
| _ ->
127+
match DateTimeOffset.TryParse (x, CultureInfo.InvariantCulture, DateTimeStyles.None) with
128+
| true, x -> Some x
129+
| _ -> None
116130
#endif
117131

118132
static member inline Invoke (value: string) =
119133
let inline call_2 (a: ^a, b: ^b) = ((^a or ^b) : (static member TryParse : _*_ -> _) b, a)
120134
let inline call (a: 'a) = fun (x: 'x) -> call_2 (a, Unchecked.defaultof<'r>) x : 'r option
121135
call Unchecked.defaultof<TryParse> value
122136

123-
type TryParse with
124-
static member inline TryParse (_: 'R, _: Default2) = fun x ->
137+
/// The F# signature
138+
static member inline InvokeOnInstance (value: string) = (^R: (static member TryParse : string -> 'R option) value)
139+
140+
/// The .Net signature
141+
static member inline InvokeOnConvention (value: string) =
125142
let mutable r = Unchecked.defaultof< ^R>
126-
if (^R: (static member TryParse : _ * _ -> _) (x, &r)) then Some r else None
143+
if (^R: (static member TryParse : _ * _ -> _) (value, &r)) then Some r else None
144+
145+
#if NET7_0
146+
/// IParsable<'T>
147+
static member InvokeOnInterface<'T when 'T :> IParsable<'T>> (value: string) =
148+
let mutable r = Unchecked.defaultof<'T>
149+
if ('T.TryParse(value, CultureInfo.InvariantCulture, &r)) then Some r else None
150+
#endif
127151

128-
static member inline TryParse (_: ^t when ^t: null and ^t: struct, _: Default1) = id
129-
static member inline TryParse (_: 'R, _: Default1) = fun x -> (^R: (static member TryParse : string -> 'R option) x)
130152

131153
type Parse =
132154
inherit Default1
133-
static member inline Parse (_: ^R , _: Default1) = fun (x:string) -> (^R: (static member Parse : _ -> ^R) x)
134155
static member inline Parse (_: ^R , _: Parse ) = fun (x:string) -> (^R: (static member Parse : _ * _ -> ^R) (x, CultureInfo.InvariantCulture))
135156

136157
static member inline Parse (_: 'T when 'T : enum<_>, _: Parse ) = fun (x:string) ->
@@ -139,6 +160,16 @@ type Parse =
139160
| _ -> invalidArg "value" ("Requested value '" + x + "' was not found.")
140161
) : 'enum
141162

163+
#if !FABLE_COMPILER
164+
static member Parse (_: DateTime , _: Parse) = fun (x:string) ->
165+
match DateTime.TryParseExact (x, [|"yyyy-MM-ddTHH:mm:ss.fffZ"; "yyyy-MM-ddTHH:mm:ssZ"|], null, DateTimeStyles.RoundtripKind) with
166+
| true, x -> x
167+
| _ -> DateTime.Parse (x, CultureInfo.InvariantCulture)
168+
169+
static member Parse (_: DateTimeOffset, _: Parse) = fun (x:string) ->
170+
try DateTimeOffset.ParseExact (x, [|"yyyy-MM-ddTHH:mm:ss.fffK"; "yyyy-MM-ddTHH:mm:ssK"|], null, DateTimeStyles.AssumeUniversal)
171+
with _ -> DateTimeOffset.Parse (x, CultureInfo.InvariantCulture)
172+
#endif
142173

143174
static member Parse (_: bool , _: Parse) = fun (x:string) -> Boolean.Parse (x)
144175

@@ -151,4 +182,46 @@ type Parse =
151182
let inline call (a: 'a) = fun (x: 'x) -> call_2 (a, Unchecked.defaultof<'r>) x : 'r
152183
call Unchecked.defaultof<Parse> value
153184

185+
static member inline InvokeOnInstance (value: string) = (^R: (static member Parse : _ -> ^R) value)
186+
187+
188+
type Parse with
189+
190+
static member inline Parse (_: ^R , _: Default4) = fun (value: string) ->
191+
match TryParse.InvokeOnConvention value with
192+
| Some x -> x : ^R
193+
| None -> invalidArg "value" ("Error parsing value '" + value + "'.")
194+
195+
static member inline Parse (_: ^R , _: Default3) = fun (value: string) ->
196+
match TryParse.InvokeOnInstance value with
197+
| Some x -> x : ^R
198+
| None -> invalidArg "value" ("Error parsing value '" + value + "'.")
199+
200+
static member inline Parse (_: ^R , _: Default2) : string -> ^R = Parse.InvokeOnInstance
201+
202+
#if NET7_0
203+
static member Parse<'T when 'T :> IParsable<'T>> (_: 'T, _: Default1) = fun (x: string) -> 'T.Parse (x, CultureInfo.InvariantCulture)
204+
static member inline Parse (_: ^t when ^t: null and ^t: struct, _: Default1) = id
205+
#else
206+
static member inline Parse (_: ^t when ^t: null and ^t: struct, _: Default2) = id
207+
#endif
208+
209+
type TryParse with
210+
211+
static member inline TryParse (_: 'R, _: Default4) : string -> 'R option = fun (value: string) ->
212+
try Some (Parse.InvokeOnInstance value) with
213+
| :? ArgumentNullException | :? FormatException -> None
214+
| _ -> reraise ()
215+
216+
static member inline TryParse (_: 'R, _: Default3) : string -> 'R option = TryParse.InvokeOnConvention
217+
218+
static member inline TryParse (_: 'R, _: Default2) : string -> 'R option = TryParse.InvokeOnInstance
219+
220+
#if NET7_0
221+
static member inline TryParse (_: 'R, _: Default1) : string -> 'R option = TryParse.InvokeOnInterface
222+
static member inline TryParse (_: ^t when ^t: null and ^t: struct, _: Default1) = id
223+
#else
224+
static member inline TryParse (_: ^t when ^t: null and ^t: struct, _: Default2) = id
225+
#endif
226+
154227
#endif

0 commit comments

Comments
 (0)