diff --git a/ch12.md b/ch12.md index 2da8c85c..3709dea6 100644 --- a/ch12.md +++ b/ch12.md @@ -45,7 +45,7 @@ Let's rearrange our types using `sequence`: sequence(List.of, Maybe.of(['the facts'])); // [Just('the facts')] sequence(Task.of, new Map({ a: Task.of(1), b: Task.of(2) })); // Task(Map({ a: 1, b: 2 })) sequence(IO.of, Either.of(IO.of('buckle my shoe'))); // IO(Right('buckle my shoe')) -sequence(Either.of, [Either.of('wing')]); // Right(['wing']) +sequence(List.of, Either.of(['wing'])); // List(Right('wing')) sequence(Task.of, left('wing')); // Task(Left('wing')) ``` diff --git a/support/index.js b/support/index.js index 31d5ab23..6dd876c3 100644 --- a/support/index.js +++ b/support/index.js @@ -147,6 +147,7 @@ class Left extends Either { return `Left(${inspect(this.$value)})`; } + // ----- Functor (Either a) map() { return this; @@ -219,7 +220,7 @@ class Right extends Either { } traverse(of, fn) { - fn(this.$value).map(Either.of); + return fn(this.$value).map(Either.of); } } @@ -360,11 +361,16 @@ class Map { .reduce((acc, k) => fn(acc, this.$value[k], k), zero); } + // ----- Pointed Map + static of(x) { + return new Map(x); + } + // ----- Functor (Map a) map(fn) { return this.reduceWithKeys( (m, v, k) => m.insert(k, fn(v)), - new Map({}), + Map.of({}), ); } @@ -376,7 +382,7 @@ class Map { traverse(of, fn) { return this.reduceWithKeys( (f, a, k) => fn(a).map(b => m => m.insert(k, b)).ap(f), - of(new Map({})), + of(Map.of({})), ); } } diff --git a/support/package.json b/support/package.json index 5b354e16..562c2646 100644 --- a/support/package.json +++ b/support/package.json @@ -19,7 +19,6 @@ "guide", "fp" ], - "dependencies": {}, "devDependencies": { "eslint": "^5.9.0", "eslint-config-airbnb": "^16.1.0",