3 ms·
One thing that is missing from Go is computation expressions (in C# 7.0 async/await was generalized to a computation expression). Computation expressions are ex
by nymanjon 7y ago
One thing that is missing from Go is computation expressions (in C# 7.0 async/await was generalized to a computation expression). Computation expressions are extremely powerful feature in F# which introduced the idea of async/await. If it is generalized then you can properly handle code failures better.
In the Go community they have found returning the result/error tuple is tedious enough that people don't properly handle their errors. I would argue this is because of the lack of generics and computation expressions.
In F# I can do something like this:
let result : Task<Result<MyObject, Error> = asyncResult {
let! validatedObject = validateObject object
let! dbObject = GetSomethingFromTheDatabase object
return dbObject
}
doSideAffectLastCodeAndHandleAnyErrors result
This lets you create little DSLs and code that you can handle errors in a central location and in your main code just get the work done without thinking about it. Makes for a really great workflow.
See also https://github.com/louthy/language-ext https://github.com/louthy/language-ext