Add Option.ofPair
See original GitHub issueIs 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?
Issue Analytics
- State:
- Created 8 months ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Option (FSharpPlus)
Applies an option value to an option function. ... An option of the function applied to the value, or None if either the...
Read more >Adding to a vector of pair - c++
I have a vector of pair like such: vector<pair<string,double>> revenue;. I want to add a string and a double from a map ...
Read more >Options - F# | Microsoft Learn
Learn how to use F# option types when an actual value might not exist for a named value or variable.
Read more >Priority Queue of Pair in Java with Examples
PriorityQueue Implementing Min Heap Based on Keys of Pair. 1. Using Lambda Expression: ... Adding objects of Pair<K, V> class by passing.
Read more >Pair in C++ Standard Template Library (STL)
Pair is used to combine together two values that may be of different data types. Pair provides a way to store two heterogeneous...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

@njlr
I think adding
Option.ofPair(the name does not matter) is nice since not everyone (including me) is super comfortable with SRTP =)I was curious if this works now; it compiles but the behaviour is incorrect: https://github.com/fable-compiler/Fable/issues/3332