Each, a maco library that creates monadic expression, released
杨博 <[email protected]>
| Newsgroups | gmane.comp.lang.scala,gmane.comp.lang.scala.user,gmane.comp.lang.scala.scalaz |
|---|---|
| Message-ID | <CA+nJC954O4OSgThAOpRb0RsKDTDOqfhLL_0-eP-V4yhBFwSeHg@mail.gmail.com> |
Hello, all,
I am glad to announce Each <https://github.com/ThoughtWorksInc/each>, a new
library that converts native imperative syntax to scalaz's monadic
expression.
Each allows you create monadic expression in a pretty simple way.
import com.thoughtworks.each.Monadic._import scalaz.std.scalaFuture._
// Returns a Future of the sum of the length of each string in each
parameter Future,// without blocking any thread.def concat(future1:
Future[String], future2: Future[String]): Future[Int] =
monadic[Future] {
future1.each.length + future2.each.length
}
import com.thoughtworks.each.Monadic._import scalaz.std.option._
def plusOne(intOption: Option[Int]) = monadic[Option] {
intOption.each + 1
}
assertEquals(None, plusOne(None))
assertEquals(Some(16), plusOne(Some(15)))
import com.thoughtworks.each.Monadic._import scalaz.std.list._
def plusOne(intSeq: List[Int]) = monadic[List] {
intSeq.each + 1
}
assertEquals(Nil, plusOne(Nil))
assertEquals(List(16), plusOne(List(15)))
assertEquals(List(16, -1, 10), plusOne(List(15, -2, 9))
We also provided a generic monad implementation for all types that support
for comprehension. The ComprehensionImplicits is able to implicitly create
Seq monad, Set monad, Vector monad, etc.
import com.thoughtworks.each.ComprehensionImplicits._import
com.thoughtworks.each.Monadic._def plusOne(intSeq: Seq[Int]) =
monadic[Seq] {
intSeq.each + 1
}
assertEquals(Seq.empty, plusOne(Seq.empty))
assertEquals(Seq(16), plusOne(Seq(15)))
assertEquals(Seq(16, -1, 10), plusOne(Seq(15, -2, 9)))
Each is like Effectful <https://github.com/pelotom/effectful>, except we
support fully-featured Scala expressions in our monadic block, while
Effectful only supports a subset of Scala expressions.
The project URL: https://github.com/ThoughtWorksInc/each
Thanks to all contributors
<https://github.com/ThoughtWorksInc/each/graphs/contributors> in
ThoughtWorks Xi'an office.
Cheers,
--
杨博 (Yang Bo)
--
You received this message because you are subscribed to the Google Groups "scala-language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
For more options, visit https://groups.google.com/d/optout.