scalaz and lift functions

As I was working through some content on the Reader monoid, I realized I wanted to lift a function to use it. If you read the Scala In Depth book, which as a really great book, you know that lifting a function to be monoidal could be useful.

The classic example is to lift the function so that the arguments as well as the return value are all Option types. Then, if any of the parameters to the new lifted function are None, the function returns None. Otherwise it would return Some.

The key thought is that you do not have to write your own, scalaz already supports lift.

It turns out that scalaz has support for lifting functions using your monoid of choice. Below is a transcript using scala REPL  with a -cp set to the scalaz core library:

See the entire post on github.



Comments

Popular posts from this blog

quick note on scala.js, react hooks, monix, auth

zio environment and modules pattern: zio, scala.js, react, query management

user experience, scala.js, cats-effect, IO