From af5e51d85b4947296d6496e5c5191b470821e9ec Mon Sep 17 00:00:00 2001 From: elycruz <603428+elycruz@users.noreply.github.com> Date: Sun, 13 Jun 2021 09:32:19 -0400 Subject: [PATCH] #42 - Added missing changes from previous commit. --- packages/fjl/src/data/monad.ts | 4 +- packages/fjl/tests/data/monad_test.ts | 100 +++++++++++++------------- 2 files changed, 52 insertions(+), 52 deletions(-) diff --git a/packages/fjl/src/data/monad.ts b/packages/fjl/src/data/monad.ts index ee6491c4..918849b2 100644 --- a/packages/fjl/src/data/monad.ts +++ b/packages/fjl/src/data/monad.ts @@ -34,8 +34,8 @@ export class MonadBase implements Monad { } static liftA2(fn, appA: Applicative, appB: Applicative): Applicative { - return (this.constructor as ApplicativeConstructor).of( - fn(appA.valueOf(), appB.valueOf) + return (appA.constructor as ApplicativeConstructor).of( + fn(appA.valueOf(), appB.valueOf()) ); } diff --git a/packages/fjl/tests/data/monad_test.ts b/packages/fjl/tests/data/monad_test.ts index 87816bb4..fd021a64 100644 --- a/packages/fjl/tests/data/monad_test.ts +++ b/packages/fjl/tests/data/monad_test.ts @@ -5,66 +5,66 @@ import {Applicative, FunctorMapFn} from "../../src/types"; import {id} from "../../src/function"; describe('#valueOf()', () => { - (<[Monad, any][]>[ - [just(20), 20], - [just(null), null], - [right(20), 20], - [left('Oh no ... an error occurred.'), 'Oh no ... an error occurred.'], - ]) - .forEach(([monad, expectedValue]) => { - it(`valueOf(${monad}) === ${expectedValue}`, () => { - expect(valueOf(monad)).toEqual(expectedValue); - }); - }) + (<[Monad, any][]>[ + [just(20), 20], + [just(null), null], + [right(20), 20], + [left('Oh no ... an error occurred.'), 'Oh no ... an error occurred.'], + ]) + .forEach(([monad, expectedValue]) => { + it(`valueOf(${monad}) === ${expectedValue}`, () => { + expect(valueOf(monad)).toEqual(expectedValue); + }); + }) }); describe('#join()', () => { - it(`join === valueOf`, () => { - expect(join).toEqual(valueOf); - }); + it(`join === valueOf`, () => { + expect(join).toEqual(valueOf); + }); }); describe('#fmap()', () => { - (<[Monad, FunctorMapFn, Monad][]>[ - [nothing(), id, nothing()], - [just(null), id, just(null)], - [just(2), x => x * 2, just(4)], - [[1, 2, 3], x => x * 2, [2, 4, 6]] - ]) - .forEach(([monad, mapper, monad2]) => { - it(`fmap(${mapper}, ${monad}).valueOf() == ${monad2}.valueOf()`, function () { - const rslt = fmap(mapper, monad) as Monad; - expect(rslt.valueOf()).toEqual(monad2.valueOf()); - }); - }) + (<[Monad, FunctorMapFn, Monad][]>[ + [nothing(), id, nothing()], + [just(null), id, just(null)], + [just(2), x => x * 2, just(4)], + [[1, 2, 3], x => x * 2, [2, 4, 6]] + ]) + .forEach(([monad, mapper, monad2]) => { + it(`fmap(${mapper}, ${monad}).valueOf() == ${monad2}.valueOf()`, function () { + const rslt = fmap(mapper, monad) as Monad; + expect(rslt.valueOf()).toEqual(monad2.valueOf()); + }); + }) }); describe('#ap', () => { - (<[Applicative<(x: T) => T>, Monad, Monad][]>[ - [just((x: number) => x * 2), just(4), just(8)], - [just((x: number) => x * 3), just(2), just(6)], - [just(x => x), nothing(), nothing()], - [just(x => x), just(null), just(null)] - ]) - .forEach(([applicative, functor, expected]) => { - it(`${applicative}`, function () { - const rslt = ap(applicative, functor) as Monad; - expect(rslt.join()).toEqual(expected.join()); - }); - }); + (<[Applicative<(x: T) => T>, Monad, Monad][]>[ + [just((x: number) => x * 2), just(4), just(8)], + [just((x: number) => x * 3), just(2), just(6)], + [just(x => x), nothing(), nothing()], + [just(x => x), just(null), just(null)] + ]) + .forEach(([applicative, functor, expected]) => { + it(`${applicative}`, function () { + const rslt = ap(applicative, functor) as Monad; + expect(rslt.join()).toEqual(expected.join()); + }); + }); }); describe('#flatMap', () => { - (<[Monad, FunctorMapFn, Monad][]>[ - [nothing(), id, nothing()], - [just(null), id, just(null)], - [just(2), x => x * 2, just(4)], - [[1, 2, 3], x => x * 2, [2, 4, 6]] - ]) - .forEach(([monad, mapper, monad2]) => { - it(`flatMap(${mapper}, ${monad}).valueOf() == ${monad2}.valueOf()`, function () { - const rslt = flatMap(mapper, monad) as Monad; - expect(rslt.valueOf()).toEqual(monad2.valueOf()); - }); - }) + (<[Monad, FunctorMapFn, Monad][]>[ + [nothing(), id, nothing()], + [just(null), id, just(null)], + [just(2), x => x * 2, just(4)], + [[1, 2, 3], x => x * 2, [2, 4, 6]] + ]) + .forEach(([monad, mapper, monad2]) => { + it(`flatMap(${mapper}, ${monad}).valueOf() == ${monad2}.valueOf()`, function () { + const rslt = flatMap(mapper, monad) as Monad; + expect(rslt.valueOf()).toEqual(monad2.valueOf()); + }); + }) });