I have a case where I have a list of rules that can disqualify a particular item (a command). Each of the rules is a high order function. (For reusability).
At the end I need to verify what rule caused the failure. How can I identify what rule caused the failure?
Is there a way that I can get the function name for where the function came from?
When I'm testing and I return back the function that caused the failure I'm getting a non-descriptive "" which doesn't correlate to what is actually returned.
An example of this:
object Library {
def testIf5(v:Int): Boolean = { v==5}
}
class CommandVerifier {
def doesItFail(value: Int, rules: List[(Int)=>Boolean]) {
rules.find(r=> !r(value))
}
}
val expected = testIf5
val actaul = new CommandVerifier().doesItFail(5, List(testIf5))
actual should be expected (expected)
.doesItFail
when assigning it toactaul
thinks it isUnit
. Try specifying the return type to beOption[(Int) => Boolean]
.def doesItFail(value: Int, rules: List[(Int)=>Boolean]): Option[(Int) => Boolean] = { rules.find(r => !r(value)) }
– Jordan Cutler