-
Notifications
You must be signed in to change notification settings - Fork 26
ComprehensionMonad
杨博 (Yang Bo) edited this page Jul 14, 2015
·
1 revision
We provided a monad implementation based on map, flatMap methods in an instance, and the apply method in its companion object.
We support Seq monad, Set monad and a lot of other collection monads in this way.
Simply import the implicit method in ComprehensionImplicits, and it will provide Monad for all types that supports for comprehension.
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)))