Most simply,
implicit def pipeFlatMap[I, O, A](pipe: Pipe[I, O, A]) = new {
def flatMap[B](f: A => Pipe[I, O, B]) = Pipe.flatMap(pipe, f)
}
If your Pipe
permits implementing point
, i.e. def point[I, O, A](a: A): Pipe[I, O, A]
, then implementing a full scalaz.Monad
typeclass could be useful, as Scalaz's implicits would give you flatMap
and many other monadic operations for free:
implicit def pipeMonad[I, O] = new Monad[({type λ[α]=Pipe[I, O, α]})#λ] {
// TODO implement point and bind
}