From 0672519cba35953cc86e93ae1b4f697c003db712 Mon Sep 17 00:00:00 2001 From: Kevin Hagerty Date: Wed, 9 Sep 2020 23:38:02 -0400 Subject: [PATCH 1/2] Fix start, init, concat, take, head Fix use of start and end values for start(), init(), concat() and take(). Also fix head to work correctly. --- episode_58/class-list/src/index.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/episode_58/class-list/src/index.js b/episode_58/class-list/src/index.js index 9d14040..3496974 100644 --- a/episode_58/class-list/src/index.js +++ b/episode_58/class-list/src/index.js @@ -69,11 +69,11 @@ class List { } take(count) { - return new List(this.fnGenerator, 0, count); + return new List(this.fnGenerator, this.start, this.start + count); } head() { - return this.generator.next().value; + return this.take(1).get(0); } tail() { @@ -81,7 +81,7 @@ class List { } init() { - return new List(this.fnGenerator, this.start, this.end - 1); + return new List(this.fnGenerator, this.start, this.length() - 1 ); } get(index) { @@ -139,7 +139,7 @@ class List { yield* list.entries(); } } - return new List(concatGenerator.bind(this), this.start, this.end); + return new List(concatGenerator.bind(this)); } zipWith(zipFn, list) { @@ -237,7 +237,7 @@ class List { return new List(listFn.bind(this)); } - slice(start, end) { + slice(start = this.start, end = this.end ) { return new List(this.fnGenerator, start, end); } From 407f42c898b5630080d0747f762b3054d19de9d7 Mon Sep 17 00:00:00 2001 From: Kevin Hagerty Date: Wed, 9 Sep 2020 23:57:01 -0400 Subject: [PATCH 2/2] memoize scan left --- episode_58/class-list/src/index.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/episode_58/class-list/src/index.js b/episode_58/class-list/src/index.js index 3496974..101e9e5 100644 --- a/episode_58/class-list/src/index.js +++ b/episode_58/class-list/src/index.js @@ -69,11 +69,11 @@ class List { } take(count) { - return new List(this.fnGenerator, this.start, this.start + count); + return new List(this.fnGenerator, 0, count); } head() { - return this.take(1).get(0); + return this.generator.next().value; } tail() { @@ -81,7 +81,7 @@ class List { } init() { - return new List(this.fnGenerator, this.start, this.length() - 1 ); + return new List(this.fnGenerator, this.start, this.end - 1); } get(index) { @@ -139,7 +139,7 @@ class List { yield* list.entries(); } } - return new List(concatGenerator.bind(this)); + return new List(concatGenerator.bind(this), this.start, this.end); } zipWith(zipFn, list) { @@ -237,7 +237,7 @@ class List { return new List(listFn.bind(this)); } - slice(start = this.start, end = this.end ) { + slice(start, end) { return new List(this.fnGenerator, start, end); } @@ -262,7 +262,8 @@ class List { yield accumulator; } } - return new List(scanLGenerator.bind(this), this.start, this.end); + // a poor way of memoization -- using toList and fromList + return List.fromList( new List(scanLGenerator.bind(this), this.start, this.end).toList() ); } scanr(scanFn, accumulator) {