Added a flag on takeWhile to allow it to include the final element, #21330
This commit is contained in:
parent
7eb660b497
commit
a28d2c579f
9 changed files with 120 additions and 30 deletions
|
|
@ -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 {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue