Dart - How to access FSharpResult in Dart #3374
Replies: 2 comments 1 reply
-
This is a good question :) You could check the For now, your best option is probably to declare some type aliases and extensions to wrap fable_library types and functions to make them more palatable when using them from Dart. For example, // The location of fable_modules will depend on the outDir of the Fable compilation
// We are also considering to distribute fable_library as a package in pub.dev
import './fable_modules/fable_library/Choice.dart' as choice;
typedef Result<Ok, Error> = choice.FSharpResult$2<Ok, Error>;
extension ResultExt<Ok, Error> on Result<Ok, Error> {
Result<Ok2, Error> map<Ok2>(Ok2 Function(Ok) f) {
return choice.Result_Map(f, this);
}
}
// Usage
Result<double, String> test(Result<int, String> res) {
return res.map((x) => x + 5);
} |
Beta Was this translation helpful? Give feedback.
-
FSharpResult is a type used in F# to represent the result of an operation, which can be either successful (represented by an Ok value) or failed (represented by an Error value). To access these values in Dart, you can define a corresponding Result class and use it to represent the FSharpResult type. |
Beta Was this translation helpful? Give feedback.
-
I am looking at reusing some F# code in my Flutter app and there are some F# functions that return FSharpResult, how can I access Ok/Error values in Dart?
Beta Was this translation helpful? Give feedback.
All reactions