I am relatively new to Scala, and just trying to get my head around the use of partially applied functions to solve my problem.
My problem is that in my code I have the following foreach logic in multiple places:
for (teamType <- TeamType.allTypes) {
findViewById(teamType.layoutID).findViewById(buttonID)
.setOnClickListener(matchButtonOnClickListener)
}
and again here:
for (teamType <- TeamType.allTypes) refreshTeamStatisticViews(teamType)
Basically, for each teamType in the TeamType case object, I am looking to perform a function that returns Unit
What I was thinking of doing is moving the foreach part into the TeamType case object, and then have that take a function or partially applied function that returns Unit.
So for example, TeamType would contain the following:
def forAllTeamTypes(fun: TeamType => Unit) = for(teamType <- allTypes) fun(teamType)
and for the second example above, I could change it to
TeamType.forAllTeamTypes(refreshTeamStatisticViews)
However, I am not sure how to apply this for partially applied functions for the more complex first example.
Can someone help me?