Halloween Kata Solutions

Here are my solutions to the Halloween Kata using Eclipse Collections APIs.

Top Candy

For the solutions, I used flatCollect, toBag, topOccurrences, collect, toSet, reduce and intersect.

public void topCandy()
MutableList<Bag<Candy>> bagsOfCandy =

// Hint: Flatten the Bags of Candy into a single Bag
Bag<Candy> bigBagOfCandy =
bagsOfCandy.flatCollect(bag -> bag).toBag();

// Hint: Find the top occurrence in the bag and convert that
// to a set.
MutableSet<Candy> mostCommon =


// Hint: Find the top 10 occurrences of Candy in each of the
// bags and intersect them.
MutableSet<Candy> commonInTop10 =
bag -> bag.topOccurrences(10)

Sets.mutable.with(Candy.REESES_PIECES, Candy.CRUNCH),

APIs covered in Kata

  1. flatCollect — flattens a nested collection of collections based on some attribute specified in a Function.
  2. toBag — converts a collection to a Bag.
  3. topOccurrences — find the top occurrences of items in a Bag based on their counts. The List returned will be bigger than the specified count requested if there are any ties.
  4. collect — transforms a collection from one type to another using a specified Function.
  5. toSet — converts a collection to a Set.
  6. reduce — applies a BinaryOperator to all elements of the collection, in this case a call to intersect two sets.
  7. intersect — returns the result of intersecting two sets.

Eclipse Collections is open for contributions. If you like the library, you can let us know by starring it on GitHub.