Skip to content

Instantly share code, notes, and snippets.

@malcolmgreaves
Created October 14, 2015 01:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save malcolmgreaves/481e91c4634b346a0487 to your computer and use it in GitHub Desktop.
Save malcolmgreaves/481e91c4634b346a0487 to your computer and use it in GitHub Desktop.
Convert generic function to Akka Streams Graph with FlowShape
object FunctionToFlow {
import akka.stream._
import akka.stream.scaladsl.{ FlowGraph, Flow }
def apply[A, B](f: A => B): Graph[FlowShape[A, B], Unit] =
FlowGraph.partial() { implicit b =>
val transformation = b.add(Flow[A].map(f))
new FlowShape[A, B](
transformation.inlet,
transformation.outlet
)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment