Skip to content

Instantly share code, notes, and snippets.

@jedws
Last active December 21, 2015 04:09
Show Gist options
  • Save jedws/6247542 to your computer and use it in GitHub Desktop.
Save jedws/6247542 to your computer and use it in GitHub Desktop.
import scalaz.{ Free, Functor, Monad, Scalaz, \/, syntax }
import Free._
import Scalaz.Id
import syntax.id._
import syntax.monad._
package times {
case class Times[+A](times: Vector[(Long, String)], a: A)
object Times {
implicit object TimesMonad extends Monad[Times] {
override def point[A](a: => A): Times[A] =
Times(Vector(), a)
override def bind[A, B](fa: Times[A])(f: A => Times[B]) =
f(fa.a) |> { fb => Times(fa.times ++ fb.times, fb.a) }
override def map[A, B](fa: Times[A])(f: A => B): Times[B] =
Times(fa.times, f(fa.a))
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment