kailuowang / mainecoon

transform and compose tagless final encoded algebras

Website Github

Build Status codecov Join the chat at https://gitter.im/kailuowang/mainecoon

Mainecoon is a small library built to facilitate transforming and composing tagless final encoded algebras.

Here is a quick example of how mainecoon can help:

Say we have a typical tagless encoded algebra ExpressionAlg[F[_]], with an interpreter implemented using Try

import mainecoon._
import util.Try

@finalAlg @autoFunctorK
trait ExpressionAlg[F[_]] {
  def num(i: String): F[Float]
  def divide(dividend: Float, divisor: Float): F[Float]
}

implicit object tryExpression extends ExpressionAlg[Try] {
  def num(i: String) = Try(i.toFloat)
  def divide(dividend: Float, divisor: Float) = Try(dividend / divisor)
}

With the @autoFunctorK annotation you can map an ExpressionAlg[F] to a ExpressionAlg[G], using a FunctionK[F, G], a.k.a. F ~> G.

import mainecoon.implicits._
import cats.~>

val fk : Try ~> Option = λ[Try ~> Option](_.toOption)

tryExpression.mapK(fk)
// res3: ExpressionAlg[Option] = ExpressionAlg$$anon$4@14dd7f4

Mainecoon also provides auto instance derivation for InvariantK and CartesianK.

For documentation/FAQ/guides, go to kailuowang.com/mainecoon.

Community

Discussion around mainecoon is encouraged in the Gitter channel as well as on Github issue and PR pages.

We adopted the Typelevel Code of Conduct. People are expected to follow it when discussing mainecoon on the Github page, Gitter channel, or other venues.

Copyright

Copyright (C) 2017 Kailuo Wang http://kailuowang.com