Result demo application
Some time ago I wrote a blog post with some tips, tricks, and techniques for effective use of the Result type (and Validation type)! I highly recommend going through this previous post if you have not read it yet!
Here's a quick recap:
Tips
- Use a Discriminated Unions for the error type in a Result
- If you care about all the errors rather than just the first encountered error, use a validation
Tricks
- How to combine different types of errors, useful for pipelines or validation which may be the combination of different types of error.
- How to filter out only the errors we care about from a list of errors
I thought it might be useful to create a SAFE application to demonstrate how someone might chain some of these techniques together.
https://github.com/CompositionalIT/username-signup-result-demo
Notable features:
Thanks to Fable we only need to write the validation in one place - then it can be run in the broswer and also server-side.
-
Local validation
- Quick
- Insecure, can be bypassed by users
- Can't do all checks e.g. DB checks
-
Remote validation
- Slower (requires a network round trip)
- Secure - can't be skipped!
- More accurate e.g. Can perform DB checks