Created
July 23, 2011 02:09
-
-
Save philipschwarz/1100862 to your computer and use it in GitHub Desktop.
Functional answer to Naresh Jain's challenge using Jedi
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int calculateAveragePreviousPercentageComplete() { return reduceAndAverageActivitiesBy(PREVIOUS_PERCENTAGE_COMPLETE); } | |
int calculateAverageCurrentPercentageComplete() { return reduceAndAverageActivitiesBy(CURRENT_PERCENTAGE_COMPLETE); } | |
int calculateAverageProgressPercentage() { return reduceAndAverageActivitiesBy(PROGRESS_PERCENTAGE); } | |
int reduceAndAverageActivitiesBy( Functor2<Integer, StudentActivityByAlbum, Integer> functor){ | |
return fold(0, activities, functor) / activities.size(); } | |
static final Functor2<Integer, StudentActivityByAlbum, Integer> PREVIOUS_PERCENTAGE_COMPLETE = | |
new Functor2<Integer, StudentActivityByAlbum, Integer>(){ | |
@Override public Integer execute(Integer accumulator, StudentActivityByAlbum value) { | |
return accumulator + value.getPreviousPercentageCompleted(); }}; | |
static final Functor2<Integer, StudentActivityByAlbum, Integer> CURRENT_PERCENTAGE_COMPLETE = | |
new Functor2<Integer, StudentActivityByAlbum, Integer>(){ | |
@Override public Integer execute(Integer accumulator, StudentActivityByAlbum value) { | |
return accumulator + value.getPercentageCompleted(); }}; | |
static final Functor2<Integer, StudentActivityByAlbum, Integer> PROGRESS_PERCENTAGE = | |
new Functor2<Integer, StudentActivityByAlbum, Integer>(){ | |
@Override public Integer execute(Integer accumulator, StudentActivityByAlbum value) { | |
return accumulator + value.getProgressPercentage(); }}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment