Assignment 6 -- PTT13


Always make sure to pull/clone/download the latest 101simplejava repo.

See the instructions here:

Starting point

Various simple OOP-like contributions could be picked as a starting point, e.g., Contribution:javaComposition.


Understand function objects and function combinators and apply them to list processing. That is, rather than using imperative for-loops in organizing queries and transformations over object graphs, use a combinator for list processing to apply simple actions or functions to individual objects.


Revise the object model such that the involved collection types for lists of departments and employees are enhanced to be amenable to the application of actions and functions to elements of the collections. This may be achieved in different ways, but one option is that the enhanced collection types support two combinators: "map" (inspired by functional programming: to apply an action (see lecture) to each element of the list; "fold" (inspired by functional programming: to apply a unary function (see lecture) to each element of the list. With this enhancement in place, the features Cut and Total are to be implemented so that combinators rather than for-loops are used.


Here is incomplete pseudo-code for the expected revision of the Cut feature:

public class Cut {
  public static void cut(Company c) {
    // An action for individual employees
    Action<Employee> ae = new Action<Employee> {
        void apply(Employee e) {
          // cut the salary in half

    // An action for individual departments
    Action<Department> ad = new Action<Department> {
        void apply(Department d) {

    // process the list of departments of a company

Thus, map takes an action and applies it to all elements of the receiving list. Without giving pseudo-code here, in the re-implementation of Total, the invocation of fold may need to receive several arguments: the function for extracting values from elements, the binary operator and the initial value for aggregating the result. Other approaches are appreciated: possibly, collection types could be enhanced differently for use with combinators (rather than for-loops).


The test cases for the features Cut and Total should be maintained to work with the re-implemented features.