Added a flag on takeWhile to allow it to include the final element, #21330

This commit is contained in:
Falmarri 2016-04-20 14:47:32 -07:00 committed by Patrik Nordwall
parent 7eb660b497
commit a28d2c579f
9 changed files with 120 additions and 30 deletions

View file

@ -92,7 +92,7 @@ final case class Filter[T](p: T ⇒ Boolean) extends SimpleLinearGraphStage[T] {
/**
* INTERNAL API
*/
final case class TakeWhile[T](p: T Boolean) extends SimpleLinearGraphStage[T] {
final case class TakeWhile[T](p: T Boolean, inclusive: Boolean = false) extends SimpleLinearGraphStage[T] {
override def initialAttributes: Attributes = DefaultAttributes.takeWhile
override def toString: String = "TakeWhile"
@ -109,6 +109,7 @@ final case class TakeWhile[T](p: T ⇒ Boolean) extends SimpleLinearGraphStage[T
if (p(elem)) {
push(out, elem)
} else {
if (inclusive) push(out, elem)
completeStage()
}
} catch {