Add Option.ofPair
AlbertoDePena opened this issue · 5 comments
Is your feature request related to a problem? Please describe.
Not a problem, just a feature request
Describe the solution you'd like
Utility method to convert
static member TryParse:
s : string *
result: byref<int>
-> bool
to Option
[<RequireQualifiedAccess>]
module Option =
let ofPair (x: bool * 'a) =
match x with
| true, y -> Some y
| false, _ -> None
let toInt32 (value: string) =
Int32.TryParse value
|> Option.ofPair
"HI" |> toInt32 // None
"10" |> toInt32 // Some 10
Describe alternatives you've considered
let tryParseInt (value: string) =
let (parsed, parsedValue) = Int32.TryParse value
if parsed then
Some parsedValue
else
None
Additional context
Please ignore if this already exists. If so, where can I find such utility method?
@TheAngryByrd you mean the SRTP is not Fable compliant correct? I wouldn't mind taking a stab at the PR
Yeah I remember it having issues with fable. I haven’t tried with the 4.0 versions though.
Great. Please ask questions if you have them!
I was curious if this works now; it compiles but the behaviour is incorrect: fable-compiler/Fable#3332
I think adding Option.ofPair
(the name does not matter) is nice since not everyone (including me) is super comfortable with SRTP =)