Skip to content

Commit 97f8ff2

Browse files
authored
Merge pull request #221 from martijnhoekstra/workaround-12137
override foldRight on BitVector/ByteVector
2 parents 0fd9976 + d13716f commit 97f8ff2

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

core/shared/src/main/scala/scodec/bits/BitVector.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -690,6 +690,13 @@ sealed abstract class BitVector
690690
new IndexedSeq[Boolean] {
691691
def length = n
692692
def apply(idx: Int): Boolean = BitVector.this.get(idx.toLong)
693+
override def foldRight[B](z: B)(op: (Boolean, B) => B): B = {
694+
val it = reverseIterator
695+
var b = z
696+
while (it.hasNext)
697+
b = op(it.next(), b)
698+
b
699+
}
693700
}
694701
}
695702
.getOrElse {

core/shared/src/main/scala/scodec/bits/ByteVector.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -706,6 +706,7 @@ sealed abstract class ByteVector
706706
new IndexedSeq[Byte] {
707707
val length = toIntSize(ByteVector.this.size)
708708
def apply(i: Int) = ByteVector.this.apply(i.toLong)
709+
override def foldRight[B](z: B)(op: (Byte, B) => B): B = ByteVector.this.foldRight(z)(op)
709710
}
710711

711712
/**

0 commit comments

Comments
 (0)