What would be the good name for this operation?

Posted by Rogach on Stack Overflow See other posts from Stack Overflow or by Rogach
Published on 2012-10-22T04:58:48Z Indexed on 2012/10/22 5:00 UTC
Read the original article Hit count: 313

Filed under:

I see that Scala standard library misses the method to get ranges of objects in the collection, that satisfy the predicate:

def <???>(p: A => Boolean): List[List[A]] = {
  val buf = collection.mutable.ListBuffer[List[A]]()
  var elems = this.dropWhile(e => !p(e))
  while (elems.nonEmpty) {
    buf += elems.takeWhile(p)
    elems = elems.dropWhile(e => !p(e))
  }
  buf.toList
}

What would be the good name for such method? And is my implementation good enough?

© Stack Overflow or respective owner

Related posts about scala