mirror of
https://github.com/gitbucket/gitbucket.git
synced 2025-11-07 05:55:51 +01:00
Initial Import.
This commit is contained in:
22
src/main/scala/util/Implicits.scala
Normal file
22
src/main/scala/util/Implicits.scala
Normal file
@@ -0,0 +1,22 @@
|
||||
package util
|
||||
|
||||
object Implicits {
|
||||
implicit def extendsSeq[A](seq: Seq[A]) = new {
|
||||
|
||||
def splitWith(condition: (A, A) => Boolean): Seq[Seq[A]] = split(seq)(condition)
|
||||
|
||||
@scala.annotation.tailrec
|
||||
private def split[A](list: Seq[A], result: Seq[Seq[A]] = Nil)(condition: (A, A) => Boolean): Seq[Seq[A]] = {
|
||||
list match {
|
||||
case x :: xs => {
|
||||
xs.span(condition(x, _)) match {
|
||||
case (matched, remained) => split(remained, result :+ (x :: matched))(condition)
|
||||
}
|
||||
}
|
||||
case Nil => result
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user