Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/main/scala/gov/wicourts/json/formlet/Formlet.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down