Skip to content

Instantly share code, notes, and snippets.

@minosiants
Created June 3, 2013 07:27
Show Gist options
  • Save minosiants/5696585 to your computer and use it in GitHub Desktop.
Save minosiants/5696585 to your computer and use it in GitHub Desktop.
Scalaz Endo
//https://github.com/debasishg/scala-snippets/blob/master/src/main/scala/endofluent.scala
//http://debasishg.blogspot.com.au/2013/02/a-dsl-with-endo-monoids-for-free.html
object Somescala extends App {
// import endodsl._
// val now = Calendar.getInstance.getTime
// val p =
// project("xenos", now) {
// for {
// a <- task("study requirements")
// b <- task("do analysis")
// _ <- b dependsOn a
// c <- task("design & code")
// _ <- c dependsOn b
// d <- c dependsOn a
// } yield d
// }
// println(p)
case class Cup(content:List[String]=Nil)
val withSugar:Endo[Cup] = ((cup:Cup)=>cup.copy(content="sugar"::cup.content)).endo
val withCoffee:Endo[Cup] = ((cup:Cup)=>cup.copy(content="coffee"::cup.content)).endo
val withWater:Endo[Cup] = ((cup:Cup)=>cup.copy(content="water"::cup.content)).endo
def cup():Endo[Cup]=((cup:Cup) => Cup()).endo
val emptyCup=Monoid[Endo[Cup]].zero
println(emptyCup compose withSugar )
//def cupOfCoffee(cup:Cup)=(withCoffee |+| withSugar |+| withWater).zero
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment