Add Scala 2.12 equivalent Iterator apply method for ByteString
This commit is contained in:
parent
44d03df694
commit
c4e33c3972
2 changed files with 20 additions and 0 deletions
|
|
@ -814,6 +814,13 @@ class ByteStringSpec extends AnyWordSpec with Matchers with Checkers {
|
|||
}
|
||||
}
|
||||
|
||||
"created from iterator" in {
|
||||
check { (a: ByteString) =>
|
||||
val asIterator = a.iterator
|
||||
ByteString(asIterator) == a
|
||||
}
|
||||
}
|
||||
|
||||
"compacting" in {
|
||||
check { (a: ByteString) =>
|
||||
val wasCompact = a.isCompact
|
||||
|
|
|
|||
|
|
@ -39,6 +39,11 @@ object ByteString {
|
|||
*/
|
||||
def apply(bytes: Byte*): ByteString = CompactByteString(bytes: _*)
|
||||
|
||||
/**
|
||||
* Creates a new ByteString by iterating over bytes.
|
||||
*/
|
||||
def apply(bytes: Iterator[Byte]): ByteString = CompactByteString(bytes)
|
||||
|
||||
/**
|
||||
* Creates a new ByteString by converting from integral numbers to bytes.
|
||||
*/
|
||||
|
|
@ -945,6 +950,14 @@ object CompactByteString {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new CompactByteString by traversing bytes.
|
||||
*/
|
||||
def apply(bytes: Iterator[Byte]): CompactByteString = {
|
||||
if (bytes.isEmpty) empty
|
||||
else ByteString.ByteString1C(bytes.toArray)
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new CompactByteString by converting from integral numbers to bytes.
|
||||
*/
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue