学习Scalaz的骑士任务示例
http://eed3si9n.com/learning-scalaz/A-knights-quest.html
之前
def in3: List[KnightPos] =
for {
first <- move
second <- first.move
third <- second.move
} yield third
def canReachIn3(end: KnightPos): Boolean = in3 contains end
Run Code Online (Sandbox Code Playgroud)
之后(使用scalaz.Endomorphic)
val moveK: Kleisli[List, KnightPos, KnightPos] = Kleisli(_.move)
def in(n: Int): List[KnightPos] =
moveK.endo.multiply(n).run.run(this)
def canReachIn(n: Int, end: KnightPos): Boolean = in(n) contains end
Run Code Online (Sandbox Code Playgroud)
https://gist.github.com/xuwei-k/c77aa4e19c0b4d4c10e2/revisions