Skip to content

Commit

Permalink
improve code coverage by leveraging invariants
Browse files Browse the repository at this point in the history
  • Loading branch information
johnynek committed Aug 20, 2018
1 parent 1d7dcc5 commit 02a2c00
Showing 1 changed file with 7 additions and 13 deletions.
20 changes: 7 additions & 13 deletions core/src/main/scala/cats/data/Chain.scala
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,9 @@ sealed abstract class Chain[+A] {
else tail ++ rights.reduceLeft((x, y) => Append(y, x))
result = Some((seq.head, next))
case Empty =>
if (rights.isEmpty) {
result = None
} else {
c = rights.last
rights.trimEnd(1)
}
// Empty is only top level, it is never internal to an Append
if (rights.nonEmpty) throw new IllegalStateException(s"found internal Empty in $this")
result = None
}
}
// scalastyle:on null
Expand Down Expand Up @@ -297,12 +294,9 @@ sealed abstract class Chain[+A] {
else rights.reduceLeft((x, y) => Append(y, x))
rights.clear()
case Empty =>
if (rights.isEmpty) {
c = null
} else {
c = rights.last
rights.trimEnd(1)
}
// Empty is only top level, it is never internal to an Append
if (rights.nonEmpty) throw new IllegalStateException(s"found internal Empty in $this")
c = null
}
}
}
Expand Down Expand Up @@ -462,7 +456,7 @@ object Chain extends ChainInstances {
currentIterator = seq.iterator
currentIterator.next
case Empty =>
go // This shouldn't happen
throw new java.util.NoSuchElementException("next called on empty iterator")
}
}

Expand Down

0 comments on commit 02a2c00

Please sign in to comment.