Type safe checking of arbitary properties (custom class) for without boilerplate code

Depending on your degree of eagerness to use this construct…

  1. Only pull it in where the frequency of usage justifies the boilerplate overhead.
  2. Write some helpers to reduce boilerplate.
  3. Consider implementing some macro on top (in contrast to the reflection-based approach used by HavePropertyMatcherGenerator)

Naive suggestion for 2:

def mkPropEqMatcher[T, V](
    name: String, extr: T => V)(
    expVal: V
): HavePropertyMatcher[T, V] =
  (t: T) => 
    HavePropertyMatchResult(extr(t) == expVal, name, expVal, extr(t))

val title = mkPropEqMatcher("title", (_: Book).title) _
val author = mkPropEqMatcher("author", (_: Book).author) _