Menu

A comprehensive introduction to Cats-mtl

MTL is a library for composing monad transformers and making it easier to work with nested monad transformer stacks. It originates from the land of Haskell, but has made it into Scala a long time ago. For the longest time however, it was barely usable, because of a bunch of...

Variance of Monad Transformers

A question that repeatedly pops up about Cats is why monad transformer types like OptionT and EitherT aren’t covariant like their Option and Either counterparts. This blog post aims to answer that question. Covariance What does it mean to say that Option is covariant? It means that an Option[B] is...

Chain – Replacing the List Monoid

List is a great data type, it is very simple and easy to understand. It has very low overhead for the most important functions such as fold and map and also supports prepending a single element in constant time. Traversing a data structure with something like Writer[List[Log], A] or ValidatedNel[Error,...

Http4s error handling with Cats Meow MTL

As a longtime http4s user I keep on learning new things and I’m always trying to come up with the best practices for writing http applications. This time I want to talk about my latest achievements in error handling within the context of an http application where it basically means...

Refactoring with Monads

I was recently cleaning up some Scala code I’d written a few months ago when I realized I had been structuring code in a very confusing way for a very long time. At work, we’ve been trying to untangle the knots of code that get written by different authors at...

Testing in the wild

Writing tests seems like a wonderful idea in theory but real systems can be a real pain to test. Today I want to show a few tips on how to use specs2 + ScalaCheck to make some real-world testing somewhat bearable. I am currently refactoring a big piece of code....

Optimizing Tagless Final – Part 2 – Monadic programs

In our previous post on optimizing tagless final programs we learned how we could use the sphynx library to derive some optimization schemes for your tagless final code. In case you missed it and want to read up on it, you can find it right here or you can watch...

Typedapi or how to derive your clients and servers from types

In this blog post, I will show you how to leverage Scala’s type system to derive an HTTP client function from a single type. This will also be the story of how I started to work on Typedapi which is basically the attempt to bring Haskell’s Servant to Scala. Servant...

Shared State in Functional Programming

Newcomers to functional programming (FP) are often very confused about the proper way to share state without breaking purity and end up having a mix of pure and impure code that defeats the purpose of having pure FP code in the first place. This is the reason that has motivated...

Tagless Final algebras and Streaming

There have been a couple of really nice blog posts about Tagless Final and some related topics. However, I have faced some design problems when writing some algebras and haven’t seen anybody talking about. So please let me introduce this problem to you. Algebra definition Given the following data definition:...