Skip to content

Instantly share code, notes, and snippets.

Created April 18, 2017 13:11
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 anonymous/c48724947085553147fc80e537d50fb5 to your computer and use it in GitHub Desktop.
Save anonymous/c48724947085553147fc80e537d50fb5 to your computer and use it in GitHub Desktop.
the description for this gist
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