F# – Retry workflow

After read­ing this old post by Don Syme, I real­ly liked the idea of wrap­ping the result of any com­pu­ta­tion into an option type to sig­ni­fy suc­cess and fail­ure cas­es and stop sub­se­quent com­pu­ta­tions on the first fail­ure. It’s neat but I want­ed to tweak a cou­ple of things to make it more use­ful:

  • excep­tion­al cas­es are not han­dled right now
  • being able to retry on excep­tions will be very use­ful
  • being able to dic­tate how many retries are made will be use­ful too

with those three points in mind, here’s the code I end­ed up with:


And some quick tests:


Let me know what you think and if there’s any­thing else I can tweak to make this more use­ful!