Skip to content

Commit

Permalink
Remove equals and hashCode overrides from NonEmptyList
Browse files Browse the repository at this point in the history
  • Loading branch information
RusticFlare committed Sep 23, 2022
1 parent e5f42ec commit 26313f2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -205,19 +205,6 @@ public class NonEmptyList<out A>(
public fun extract(): A =
this.head

override fun equals(other: Any?): Boolean {
if (this === other) return true
other?.let {
if (it::class != this::class) return false
(other as NonEmptyList<*>)
if (all != other.all) return false
return true
} ?: return false
}

override fun hashCode(): Int =
all.hashCode()

override fun toString(): String =
"NonEmptyList(${all.joinToString()})"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package arrow.core
import arrow.core.test.UnitSpec
import arrow.core.test.laws.SemigroupLaws
import arrow.typeclasses.Semigroup
import io.kotest.assertions.withClue
import io.kotest.matchers.booleans.shouldBeTrue
import io.kotest.property.Arb
import io.kotest.matchers.shouldBe
import io.kotest.property.arbitrary.boolean
Expand Down Expand Up @@ -298,7 +300,6 @@ class NonEmptyListTest : UnitSpec() {
}
}


"minBy element" {
checkAll(
Arb.nonEmptyList(Arb.int())
Expand All @@ -308,5 +309,16 @@ class NonEmptyListTest : UnitSpec() {
result shouldBe expected
}
}

"NonEmptyList equals List" {
checkAll(
Arb.nonEmptyList(Arb.int())
) { a ->
withClue("$a should be equal to ${a.all}") {
// You can't use `shouldBe` here because it doesn't use the `equals` methods on `Iterable`
(a == a.all).shouldBeTrue()
}
}
}
}
}

0 comments on commit 26313f2

Please sign in to comment.