Created
August 13, 2013 04:41
-
-
Save jedws/6217956 to your computer and use it in GitHub Desktop.
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
| import scalaz.Monad | |
| import scalaz.syntax.monad._ | |
| /** | |
| * Non stack-using Foldable substitute | |
| */ | |
| trait Folder[F[_], A] { | |
| def foldLefterM[G[_], B](z: B)(f: (B, A) => G[B])(implicit M: Monad[G]): G[B] | |
| } | |
| object Folder { | |
| implicit def FolderList[A](ls: List[A]) = | |
| new Folder[List, A] { | |
| def foldLefterM[G[_], B](z: B)(f: (B, A) => G[B])(implicit M: Monad[G]): G[B] = | |
| ls.foldLeft(z.point[G]) { | |
| case (mg, a) => mg >>= { b => f(b, a) } | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment