Created
June 3, 2013 07:27
-
-
Save minosiants/5696585 to your computer and use it in GitHub Desktop.
Scalaz Endo
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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