First release and not yet good enough from my point of view but it works almost as it should :
def cut[A, I[A]](col:I[A], test:A=>Boolean, cutright:Boolean=true)
(implicit bf: CanBuildFrom[I[A], A, I[A]],
c2i: I[A]=>Iterable[A])
: Seq[I[A]] = {
var accu = Seq.empty[I[A]]
var builder = bf()
var count=0
for { a <- col} {
test(a) match {
case false =>
builder += a
count +=1
case true if cutright =>
if (count>0) accu:+=builder.result()
builder = bf()
builder += a
count=0
case true =>
builder += a
accu:+=builder.result()
builder = bf()
count=0
}
}
accu:+=builder.result()
accu
}
// cut(Vector(0, 1, 2, 3, 0, 5, 6, 0, 7, 8, 9, 10), (x:Int) => x == 0)
//
// => List(Vector(0, 1, 2, 3), Vector(0, 5, 6), Vector(0, 7, 8, 9, 10))
view raw chisel.scala hosted with ❤ by GitHub