From 1524f5e566bbe74f331fcc7c27e1ee7be5500544 Mon Sep 17 00:00:00 2001 From: Peter Brant Date: Wed, 6 Feb 2019 17:37:38 +0100 Subject: [PATCH] Add .mapM --- src/main/scala/gov/wicourts/json/formlet/Formlet.scala | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/main/scala/gov/wicourts/json/formlet/Formlet.scala b/src/main/scala/gov/wicourts/json/formlet/Formlet.scala index d88e872..e43f5ec 100644 --- a/src/main/scala/gov/wicourts/json/formlet/Formlet.scala +++ b/src/main/scala/gov/wicourts/json/formlet/Formlet.scala @@ -8,6 +8,7 @@ import scalaz.syntax.bifunctor._ import scalaz.syntax.either._ import scalaz.syntax.monad._ import scalaz.syntax.monoid._ +import scalaz.syntax.traverse.{ToFunctorOps => _, _} import scalaz.syntax.validation._ import scala.language.higherKinds @@ -69,6 +70,13 @@ case class Formlet[M[_], N[_, _], I, V, E, A](run: I => M[(N[E, A], V)]) { ): Formlet[M, N, I, W, EE, AA] = Formlet(c => M.bind(run(c))(f.tupled)) + def mapM[B]( + f: A => M[B] + )( + implicit M: Monad[M], N: Traverse[N[E, ?]] + ): Formlet[M, N, I, V, E, B] = + mapResultM { case (n, v) => n.traverse(f).map((_, v)) } + def local[X](f: X => I): Formlet[M, N, X, V, E, A] = Formlet(run compose f) def contramap[X](f: X => I): Formlet[M, N, X, V, E, A] = local(f)