From 52a3d159b4aede9ab0a5f83b58c4429dfafb69d6 Mon Sep 17 00:00:00 2001 From: Peter David Faria Date: Fri, 7 Nov 2014 13:58:27 -0800 Subject: [PATCH 1/2] Bug fixes Fixed reduce implementations. Made concatMap an instance method of ComposableList. --- src/learnrxjava/ComposableList.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/learnrxjava/ComposableList.java b/src/learnrxjava/ComposableList.java index d1bc858..e138252 100644 --- a/src/learnrxjava/ComposableList.java +++ b/src/learnrxjava/ComposableList.java @@ -424,9 +424,9 @@ public ComposableList exercise9() { Unfortunately List doesn't have a concatMap method and there's no way for us to add one. However we _can_ define a static method concatMap. The concatMap method accepts a ComposableList , a function that accepts a single value and returns a collection (Function> ), and returns a flat list of the results (ComposableList ). */ - public static ComposableList concatMap(ComposableList that, Function> projectionFunctionThatReturnsList) { + public ComposableList concatMap(Function> projectionFunctionThatReturnsList) { ComposableList results = new ComposableList(); - for (T itemInList : that) { + for (T itemInList : this) { // ------------ INSERT CODE HERE! ---------------------------- // Apply the projection function to each item in the list. // This will create _another_ list. Then loop through each @@ -618,7 +618,7 @@ public ComposableList reduce(BiFunction combiner) { // the previous computation back into the combiner function until // we've exhausted the entire list and are left with only one function. while (counter < this.size()) { - accumulatedValue = combiner.apply(accumulatedValue, this.get(1)); + accumulatedValue = combiner.apply(accumulatedValue, this.get(counter)); counter++; } @@ -643,7 +643,7 @@ public ComposableList reduce(R initialValue, BiFunction combiner // the previous computation back into the combiner function until // we've exhausted the entire list and are left with only one function. while (counter < this.size()) { - accumulatedValue = combiner.apply(accumulatedValue, this.get(0)); + accumulatedValue = combiner.apply(accumulatedValue, this.get(counter)); counter++; } From 04c77eac58d4a604819c55b0a27e4ad18bcfdaf6 Mon Sep 17 00:00:00 2001 From: Peter David Faria Date: Fri, 7 Nov 2014 14:00:23 -0800 Subject: [PATCH 2/2] Changed return type of exercise19 for consistency. --- src/learnrxjava/ComposableList.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/learnrxjava/ComposableList.java b/src/learnrxjava/ComposableList.java index e138252..9f82ad4 100644 --- a/src/learnrxjava/ComposableList.java +++ b/src/learnrxjava/ComposableList.java @@ -749,7 +749,7 @@ public ComposableList> exercise18() { This is a variation of the problem we solved earlier, where we retrieved the url of the boxart with a width of 150px. This time we'll use reduce() instead of filter() to retrieve the smallest box art in the boxarts list. */ - public JSON exercise19() { + public ComposableList exercise19() { ComposableList movieLists = ComposableList.of( new MovieList( "New Releases",