This page is no longer maintained — Please continue to the home page at www.scala-lang.org

Re: match-based assertions (was: val 1 = 2 compiles)

No replies
Lars Hupel
Joined: 2010-06-23,
User offline. Last seen 44 weeks 3 days ago.

> I know, I was joking a bit. As said before, I'm not arguing this is the best
> style.

Well, sorry for derailing the discussion, but I'd like to argue that
this is actually quite similar to `Predef.assert` with the minor
difference that the usual assertion methods take a `Boolean`. I see no
reason why stating that "this value should match that pattern" is not a
valid use case for assertions.

Of course, one might still say that

value match {
case pattern => doStuff
case _ => sys.error("match failed!")
}

is sufficiently concise, so I'll leave this for discussion here.

Copyright © 2012 École Polytechnique Fédérale de Lausanne (EPFL), Lausanne, Switzerland