Typelevel incubator Build Status codecov Join the chat at https://gitter.im/kailuowang/mainecoon Latest version Scala.js

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)

// res3: ExpressionAlg[Option] = ExpressionAlg$$anon$4@14dd7f4

Note that the Try ~> Option is implemented using kind projector's polymorphic lambda syntax.

Behind the scene, @autoFunctorK generates an instance of the FunctorK type class that provides the mapping functionality. Mainecoon also provides type classes InvariantK and CartesianK and auto instance generations for them.

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


Any contribution is more than welcome. Also feel free to report bugs, request features using github issues or gitter.

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 (C) 2017 Kailuo Wang http://kailuowang.com


Mainecoon is licensed under the Apache License 2.0