Improved ByteString.{head,tail,last, init} and added missing tests
This commit is contained in:
parent
3b67a4fdef
commit
b6b117cf54
2 changed files with 6 additions and 4 deletions
|
|
@ -285,7 +285,9 @@ class ByteStringSpec extends WordSpec with MustMatchers with Checkers {
|
|||
}
|
||||
|
||||
"calling head" in { check { a: ByteString ⇒ a.isEmpty || likeVector(a) { _.head } } }
|
||||
"calling tail" in { check { a: ByteString ⇒ a.isEmpty || likeVector(a) { _.tail } } }
|
||||
"calling last" in { check { a: ByteString ⇒ a.isEmpty || likeVector(a) { _.last } } }
|
||||
"calling init" in { check { a: ByteString ⇒ a.isEmpty || likeVector(a) { _.init } } }
|
||||
"calling length" in { check { a: ByteString ⇒ likeVector(a) { _.length } } }
|
||||
|
||||
"calling span" in { check { (a: ByteString, b: Byte) ⇒ likeVector(a)({ _.span(_ != b) match { case (a, b) ⇒ (a, b) } }) } }
|
||||
|
|
|
|||
|
|
@ -257,10 +257,10 @@ sealed abstract class ByteString extends IndexedSeq[Byte] with IndexedSeqOptimiz
|
|||
// a parent trait.
|
||||
override def iterator: ByteIterator = throw new UnsupportedOperationException("Method iterator is not implemented in ByteString")
|
||||
|
||||
@inline final override def head: Byte = this(0)
|
||||
@inline final override def tail: ByteString = this.drop(1)
|
||||
@inline final override def last: Byte = this(this.length - 1)
|
||||
override def init: ByteString = this.take(this.length - 1)
|
||||
override def head: Byte = apply(0)
|
||||
override def tail: ByteString = drop(1)
|
||||
override def last: Byte = apply(length - 1)
|
||||
override def init: ByteString = dropRight(1)
|
||||
|
||||
override def slice(from: Int, until: Int): ByteString =
|
||||
if ((from == 0) && (until == length)) this
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue