2017-07-06

Longevity Goes Finally Tagless

Longevity - your persistence framework for Scala and NoSQL - has always sported a future-based API. But now in release 0.24, longevity has gone finally tagless, replacing the hardcoded references to scala.concurrent.Future with a generic effect F. We currently support three effects: Scala futures, the cats-effect IO monad, and an old-fashioned blocking API for the purists out there. We plan to support a variety of Task monads as effects in the near future, and you can always write your own effect as well.

For more information on longevity effects, see the user manual.

For examples on how longevity works with different effects, check out this demo code.

This release is exciting for me for many reasons. Perhaps most importantly, longevity now sports a truly functional API with support for IO monads. But the flexibility of the finally tagless approach is truly freeing. We can satisfy the purist functional programmers, and continue to support people who want to do reactive programming with futures, with a minimum of cognitive overhead. It's also exciting to me because it's a major step on my personal path to becoming a better functional programmer.

But the best part for me is just how beautiful the repository API has become. Just look at it. In a sense, this is how this API was always meant to be. Perfectly intuitive, fully typesafe, just the right level of abstraction without a hint of leaks. I couldn't imagine doing persistence in Scala any other way.

So what else comes in this release? I've removed a couple of superfluous features from the API that were not really useful and were clogging up my API. I've also started a major shift with the emblem project. This project is now officially dead. Most of what emblem does, you'd be better off using shapeless. Myself, I've moved most of the old emblem code internal to longevity, and plan to replace it with shapeless over time.

I've extracted the useful parts of emblem into their own library named typekey. This library is really cool and you should check it out. You can do similar things with shapeless Poly, but type bound maps have a much prettier API, and more likely than not, have much better performance characteristics. Having heard Miles Sabin steer people away from Poly now and then, I think type bound maps are definitely worth a look if you are looking to solve a problem with something like Poly.

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.