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 result extract

See original GitHub issue

This extension returns n as the default if none: option f n https://github.com/fsprojects/FSharpPlus/blob/master/src/FSharpPlus/Operators.fs#L39

This seems like it’s equivalent to (map f >> Option.defaultValue n).

Can we add something similar for Result?

I’d like Result.defaultValue and Result.defaultWith for similarity to existing Option functions but could also be like Haskell fromLeft/fromRight… here as fromOk/fromError https://hackage.haskell.org/package/base-4.10.0.0/docs/Data-Either.html#v:fromLeft

WDYT?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:16 (16 by maintainers)

github_iconTop GitHub Comments

2reactions
gustycommented, Jan 12, 2020

In #232 I did a concrete proposal of all the above.

Some notes:

It’s important to note the difference between Choice<_,_> and Result<_,_> the former is like the tuple but for DUs, and it’s (still) used everywhere in F# to abstract the shape of a DU while the latter is biased towards a Result-or-Error abstraction.

Therefore, some of the suggested functions makes more sense in one but not in the the other type.

In order to facilitate the use for these functions in both types we can add a simple pair of functions from one type to the other.

  • These functions are Result.toChoice and Result.ofChoice it makes more sense in the Result module as Choice is more generic, so it makes no sense to add lot of conversion in Choice to other types, it’s better for the other types to have their corresponding link to Choice.

  • The extract function makes sense in Result which has a concrete meaning of representing a value in Ok with an effect in Error. This function is called getOk but I think it should be called simply get.

  • The additional extracting functions are also available in Result for the same reason, they are called defaultValue and defaultWith.

  • As for the partition functions, they make more sense in the Choice module as @wallymathieu suggested given the inherent symmetry and general purpose. If we want to partition on Result, we can do List.partitionMap Result.toChoice x. The name partitionMap is also used in Scala libs for the same function. There is no Seq implementation for the same reason there is no unzip for Seq which is the tricky way to implement a function that yields 2 sequences (lazy?, strict?, buffering?).

1reaction
gustycommented, Jan 9, 2020

A bit off topic:

Other functions I would like to add are List.partitionOfResult and List.partitionOfChoice (also for Array and seq). See Haskell similar functions

I found them very useful in the past.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Add Data to Extracts
You can add new data to the extract by using the Append Data from Data Source command. Note: Joins or custom SQL should...
Read more >
python - How to extract multiple ints from string and append ...
You can easily do that with the pandas str operations: import pandas as pd df = pd.DataFrame({ 'Pairing': ['1001_1234_1235' ...
Read more >
Add Export Extraction Result to DataTable
Hi all,. I'm working on invoice processing. After the validation I use export extraction results activity giving a DataSet output.
Read more >
Extract data from Google Sheets cells: text, numbers, URLs ...
Insert a new column with the result to the right of the source data. Clear the extracted text from the source data. Extract...
Read more >
Extract column information using the Extract function in ...
When you apply the “Extract” function via the “Add Column” menu, a new column is created and your extracted content appears in that...
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