Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
require('fantasy-land');
const { Future } = require('fluture');
const { Identity, Either } = require('monet');
const { MonetEitherT: EitherT } = require('monad-t');
const { FlutureTMonetEither: FutureTEither } = require('monad-t');
EitherT(Identity.of(1)); // => Either.Right(1)
FutureTEither.of(Future.of(Either.Right(1))); // => FlutureTMonetEither(1)
it('tests not mapping the right', function(done) {
FlutureTMonetEither
.fromEither(Either.Right(1))
.leftMap(val => val + 1)
.fork(
noop,
(val) => {
assert.strictEqual(val, 1);
done();
}
);
});
});
it('tests lifting Either into FlutureTMonetEither', function() {
const a = Either.Right(1);
const b = liftEither(a);
assert.isTrue(isFlutureTMonetEither(b));
});
});
it('tests Either.Left in both FTEs', function(done) {
FlutureTMonetEither
.fromFuture(Future.of('val'))
.filter(always(false), 'error1')
.and(FlutureTMonetEither
.fromEither(Either.Right('val'))
.filter(always(false), 'error2')
)
.fork(
(val) => {
assert.strictEqual(val, 'error1');
done();
},
noop
);
});
});
.chainEither(() => Either.Right(2))
.fork(
const add1 = a => FlutureTMonetEither.of(Future.of(Either.Right(a + 1)));
const fe = FlutureTMonetEither.of(Future.of(Either.Right(1))).chain(add1);
.flatMap(async (data: Object): Either => {
const body: JSON = await data.json();
return data.status >= 400 ? Either.Left(body.message) : Either.Right(body);
})).catch(Either.left);
}
.then((resp: Response): Either => Either.Right(resp)
.flatMap(async (data: Object): Either => {
const body: JSON = await data.json();
return data.status >= 400 ? Either.Left(body.message) : Either.Right(body);
})).catch(Either.left);
}
ok: (c: Content): Result => Either.Right(c),
error: (e: ErrorInfo): Result => Either.Left(e),
FlutureTMonetEither.fromValue = function fromValue(val) {
return this[of](Future.of(Either.Right(val)));
};