Created
October 14, 2015 01:41
-
-
Save malcolmgreaves/481e91c4634b346a0487 to your computer and use it in GitHub Desktop.
Convert generic function to Akka Streams Graph with FlowShape
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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