Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it('traverses left to right', function() {
eq(R.commute(S.Either.of, [S.Right(1), S.Right(2)]), S.Right([1, 2]));
eq(R.commute(S.Either.of, [S.Right(1), S.Left('XXX')]), S.Left('XXX'));
eq(R.commute(S.Either.of, [S.Left('XXX'), S.Right(1)]), S.Left('XXX'));
eq(R.commute(S.Either.of, [S.Left('XXX'), S.Left('YYY')]), S.Left('XXX'));
});
LazyEither.Left('bad').value(res => {
expect(res).to.deep.equal(S.Left('bad'))
done()
})
})
LazyEither.Right(1500)[FL.chain](this.delayed).value(res => {
let endTime = Date.now()
expect(res).to.deep.equal(S.Left('Delay too long'))
expect(endTime - startTime).to.be.closeTo(0, 100)
done()
})
})
let delayed = (ms, val) => LazyEither(resolve => {
ms > 1000 ? resolve(S.Left(Error('Delay too long')))
: setTimeout(() => resolve(S.Right(val)), ms)
})
const validate = (seed, min, max, randFn) => {
if (!R.all(R.both(Number.isInteger, inRange), seed))
return S.Left(TypeError(`Seed must be an array of four integers between [${UINT32_MIN}, ${UINT32_MAX}]`))
else if (typeof min !== 'number')
return S.Left(TypeError('Min must be a number'))
else if (typeof max !== 'number')
return S.Left(TypeError('Max must be a number'))
else if (min >= max)
return S.Left(Error('Min must be less than max'))
else
return S.Right(randFn(seed, min, max))
}
return function convertMaybe(val) {
const result = monadReturningFunction(val)
return S.isJust(result) ? S.Right(result.value) : S.Left(null)
}
}
(err, data) => resolve(err != null ? S.Left(err) : S.Right(data)))
})