I’m working a bit with Scala and come up with a solution to some problem by passing a predicate to a filtering function. Not big deal but inside the predicate I used a call to a private function named doSearch.
Is doSearch method called as a regular method or passed as a “pointer” to the method and called as a high order function ?
Mi rationale is that passing it as a high order function seems is the only way to do it because doSearch is private to MyObject but could also doSearch be called from inside GlobalSet because the call is performed from inside MyObject and thus gaining access to it ?
Any pointer, suggestions and urls pointing for information are welcome !
object MyObject {
private def doSearch(text: String, wordList: List[String]): Boolean = {
// do the search
}
val thisSet: MySet = GlobalSet.allElements.filter( elem => doSearch(elem, myList) )
}
I see no reason why
doSearchshould be lifted to a function here. The closure will be translated to some anonymous class which will calldoSearch– pretty much the same way you would call some method from e.g. an anonymousActionListenerin Java.But if you really want to know what’s happening, there is always the decompiler…