2

Is it possible in scala to get syntax string representation of scala expression and use it somewhere else in code?

Lets assume we have expression:

implicit class AOps[A](a:A) {
  def require(r: A => Boolean): A = if(!r(a)) throw new Exception(s"Requirement: '${some magic code}' failed") else a
}

10.require(_ < 0) //I would expect Exception with message "Requirement: '10 < 0' failed" 

Please notice 'some magic code'. I would like to translate r into '10 < 0'.

pawel.panasewicz
  • 1,831
  • 16
  • 27

0 Answers0