Created
April 18, 2017 13:11
-
-
Save anonymous/c48724947085553147fc80e537d50fb5 to your computer and use it in GitHub Desktop.
the description for this gist
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
class MyFilterGraphStage[T](predicate: T => Boolean) extends SimpleLinearGraphStage[T] { | |
override def createLogic(inheritedAttributes: Attributes): GraphStageLogic = new GraphStageLogic(shape) with InHandler with OutHandler { | |
override def onPush() = { | |
val element = grab(in) | |
if(predicate(element)) { | |
push(out, element) | |
} else { | |
pull(in) | |
} | |
} | |
override def onPull() = pull(in) | |
setHandlers(in, out, this) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment