diff --git a/appendix_b.md b/appendix_b.md index 5ecf1859..3a23b66e 100644 --- a/appendix_b.md +++ b/appendix_b.md @@ -62,6 +62,10 @@ class Left extends Either { return false; } + static of(x) { + throw new Error('`of` called on class Left (value) instead of Either (type)'); + } + inspect() { return `Left(${inspect(this.$value)})`; } @@ -104,6 +108,10 @@ class Right extends Either { return true; } + static of(x) { + throw new Error('`of` called on class Right (value) instead of Either (type)'); + } + inspect() { return `Right(${inspect(this.$value)})`; } diff --git a/ch08.md b/ch08.md index 747e8f2e..2bff7177 100644 --- a/ch08.md +++ b/ch08.md @@ -258,7 +258,7 @@ class Left extends Either { class Right extends Either { map(f) { - return Right.of(f(this.$value)); + return Either.of(f(this.$value)); } inspect() { @@ -572,10 +572,10 @@ Even with `Task`, our `IO` and `Either` functors are not out of a job. Bear with // dbUrl :: Config -> Either Error Url const dbUrl = ({ uname, pass, db }) => { if (uname && pass && host && db) { - return Right.of(`db:pg://${uname}:${pass}@${host}5432/${db}`); + return Either.of(`db:pg://${uname}:${pass}@${host}5432/${db}`); } - return Left.of(Error('Invalid config!')); + return left(Error('Invalid config!')); }; // connectDb :: Config -> Either Error (IO DbConnection) @@ -666,7 +666,7 @@ We can instantly see and refactor code based on properties held by all functors. Functors can stack: ```js -const nested = Task.of([Right.of('pillows'), Left.of('no sleep for you')]); +const nested = Task.of([Either.of('pillows'), left('no sleep for you')]); map(map(map(toUpperCase)), nested); // Task([Right('PILLOWS'), Left('no sleep for you')])