So, cats-effect has
Resource. It’s nice. Some cats-effect users are considering making a
Resource fanclub. Why? Well, probably because of some neat things you can do with it, and two exercises here are to help you see what can be done outside of just flat-mapping some library ones and using them in the end.
These exercises are harder than previous ones. To make matters worse, I also now require
using cats-effect typeclasses instead of choosing a concrete
F. You can test it with the
effect of your choice, of course, but it must work for everything.
On a positive note, I’ve provided scastie links with test cases that I used myself - it is not enough to find all possible bugs, but should get you started quickly and check more edge cases than my previous ones.
Tearing resources apart
There’s one unsafe method on Resource, and it’s called
allocated. It gives you
access to allocator and finalizer directly. In fact, originally
have it - that’s how dangerous it is. However, it is required for some advanced
usages, like embedding a
Resource into some other datastructure.