Re: AbstractTraversable.headOption throws NoSuchElementException

Erik Osheim <[email protected]>
Newsgroups gmane.comp.lang.scala
Message-ID <[email protected]>
On Wed, May 06, 2015 at 12:58:06PM -0700, Rex Kerr wrote:
> I'm not sure there's any way to catch wonky usages of the API except to try
> them and see what happens (and submit a bug report to the offending project
> if it does something weird).

This might be overkill for Scala collections, but I could imagine
publishing a laws package that encodes the invariants for each
collection type, allowing folks to easily test their own custom
implementations against the expectations of the API/library.

For example, I could imagine testing the following properties:

    // C[A] <: Iterable[A]
    forAll { (xs: C[A]) =>
      val lst1 = xs.iterator.toList
      val lst2 = xs.iterator.toList
      lst1 shouldBe lst2

      xs.size shouldBe xs.iterator.size

      xs.isEmpty shouldBe xs.iterator.isEmpty

      // ...and so on
    }

I just thought I'd mention this, since the strategy of exporting laws
to test against has been pretty successful in the "functional" corner
of the Scala ecosystem.

-- Erik

-- 
You received this message because you are subscribed to the Google Groups "scala-language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
For more options, visit https://groups.google.com/d/optout.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.