One of the things I love about functional programming, and Scala in particular is that it feels like you can make new language constructs. One common pattern I run into is having to do something a few times until hopefully it works. This is especially relevant when you are calling some remote endpoint that might be busy, slow, or down or whatever.
I found this little gem on stackoverflow:
What’s going on here? We take an Int and a function. Then try to call the function. If it successful then return its value, else recursively call ourselves again until we run out of tries. If we haven’t succeeded in a certain number of tries then throw the exception the function gave us.
Ok so enough of that, the real story is in how easy it in to use this guy.