Add result extract
See original GitHub issueThis 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:
- Created 4 years ago
- Comments:16 (16 by maintainers)
Top 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 >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 FreeTop 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
Top GitHub Comments
In #232 I did a concrete proposal of all the above.
Some notes:
It’s important to note the difference between
Choice<_,_>
andResult<_,_>
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
andResult.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 inOk
with an effect inError
. This function is calledgetOk
but I think it should be called simplyget
.The additional extracting functions are also available in Result for the same reason, they are called
defaultValue
anddefaultWith
.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 doList.partitionMap Result.toChoice x
. The namepartitionMap
is also used in Scala libs for the same function. There is noSeq
implementation for the same reason there is nounzip
forSeq
which is the tricky way to implement a function that yields 2 sequences (lazy?, strict?, buffering?).A bit off topic:
Other functions I would like to add are
List.partitionOfResult
andList.partitionOfChoice
(also for Array and seq). See Haskell similar functionsI found them very useful in the past.