question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add Option.ofPair

See original GitHub issue

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?

Issue Analytics

  • State:closed
  • Created 8 months ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
AlbertoDePenacommented, Jan 20, 2023

@njlr

I think adding Option.ofPair (the name does not matter) is nice since not everyone (including me) is super comfortable with SRTP =)

0reactions
njlrcommented, Jan 20, 2023

I was curious if this works now; it compiles but the behaviour is incorrect: https://github.com/fable-compiler/Fable/issues/3332

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found