xod-func-tools
Advanced tools
Comparing version 0.19.0 to 0.19.2
{ | ||
"name": "xod-func-tools", | ||
"version": "0.19.0", | ||
"version": "0.19.2", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "keywords": [], |
@@ -16,16 +16,15 @@ import * as R from 'ramda'; | ||
export const rejectFetchResult = R.curry( | ||
(payload, res) => ( | ||
res.status ? | ||
Object.assign( | ||
new Error(res.statusText), | ||
{ | ||
status: res.status, | ||
statusText: res.statusText, | ||
}, | ||
payload | ||
) : | ||
Object.assign(res, payload) | ||
) | ||
(payload, res) => | ||
res.status | ||
? Object.assign( | ||
new Error(res.statusText), | ||
{ | ||
status: res.status, | ||
statusText: res.statusText, | ||
}, | ||
payload | ||
) | ||
: Object.assign(res, payload) | ||
); | ||
export default {}; |
@@ -28,3 +28,5 @@ import * as R from 'ramda'; | ||
if (oldIndex >= len || newIndex >= len) { | ||
throw new Error(`Can not swap items that out of an array: ${oldIndex} > ${newIndex}. Array length: ${len}.`); | ||
throw new Error( | ||
`Can not swap items that out of an array: ${oldIndex} > ${newIndex}. Array length: ${len}.` | ||
); | ||
} | ||
@@ -35,6 +37,5 @@ | ||
return R.pipe( | ||
R.update(oldIndex, newItem), | ||
R.update(newIndex, oldItem) | ||
)(array); | ||
return R.pipe(R.update(oldIndex, newItem), R.update(newIndex, oldItem))( | ||
array | ||
); | ||
} | ||
@@ -56,8 +57,5 @@ ); | ||
R.reduce( | ||
(acc, nextList) => R.append( | ||
R.without(R.unnest(acc), nextList), | ||
acc | ||
), | ||
(acc, nextList) => R.append(R.without(R.unnest(acc), nextList), acc), | ||
[] | ||
) | ||
); |
@@ -56,6 +56,25 @@ import * as R from 'ramda'; | ||
[Maybe.isJust, R.unnest], | ||
[Maybe.isNothing, () => { throw new Error('Maybe is expected to be Just, but its Nothing.'); }], | ||
[ | ||
Maybe.isNothing, | ||
() => { | ||
throw new Error('Maybe is expected to be Just, but its Nothing.'); | ||
}, | ||
], | ||
[Either.isRight, R.unnest], | ||
[Either.isLeft, (val) => { throw new Error(`Either expected to be Right, but its Left with value: ${val}`); }], | ||
[R.T, (input) => { throw new Error(`Maybe or Either should be passed into explode function. Passed: ${input}`); }], | ||
[ | ||
Either.isLeft, | ||
val => { | ||
throw new Error( | ||
`Either expected to be Right, but its Left with value: ${val}` | ||
); | ||
}, | ||
], | ||
[ | ||
R.T, | ||
input => { | ||
throw new Error( | ||
`Maybe or Either should be passed into explode function. Passed: ${input}` | ||
); | ||
}, | ||
], | ||
]); | ||
@@ -96,6 +115,5 @@ | ||
'explodeEither :: Either a b -> b', | ||
foldEither( | ||
(err) => { throw new Error(`Explosion failed: ${err}`); }, | ||
R.identity | ||
) | ||
foldEither(err => { | ||
throw new Error(`Explosion failed: ${err}`); | ||
}, R.identity) | ||
); | ||
@@ -110,7 +128,5 @@ | ||
// :: (() -> b) -> (a -> a) -> Maybe a -> Promise a b | ||
export const maybeToPromise = R.curry( | ||
(nothingFn, justFn, maybe) => new Promise( | ||
(resolve, reject) => ( | ||
maybe.isJust ? resolve(maybe.value) : reject() | ||
) | ||
export const maybeToPromise = R.curry((nothingFn, justFn, maybe) => | ||
new Promise( | ||
(resolve, reject) => (maybe.isJust ? resolve(maybe.value) : reject()) | ||
).then(justFn, nothingFn) | ||
@@ -130,7 +146,4 @@ ); | ||
'reduceM :: (b -> m b) -> (b -> a -> m b) -> b -> [a] -> m c', | ||
(m, fn, initial, list) => R.reduce( | ||
(acc, a) => R.chain(val => fn(val, a), acc), | ||
m(initial), | ||
list | ||
) | ||
(m, fn, initial, list) => | ||
R.reduce((acc, a) => R.chain(val => fn(val, a), acc), m(initial), list) | ||
); | ||
@@ -175,7 +188,4 @@ | ||
'leftIf :: (a -> c) -> (a -> b) -> a -> Either b c', | ||
(condition, leftFn, val) => ( | ||
condition(val) | ||
? Either.of(val) | ||
: Either.Left(leftFn(val)) | ||
) | ||
(condition, leftFn, val) => | ||
condition(val) ? Either.of(val) : Either.Left(leftFn(val)) | ||
); |
@@ -28,16 +28,7 @@ import * as R from 'ramda'; | ||
(keys, input) => { | ||
const isPlainObject = R.both( | ||
R.is(Object), | ||
R.complement(R.is(Array)) | ||
); | ||
const isPlainObject = R.both(R.is(Object), R.complement(R.is(Array))); | ||
return R.compose( | ||
R.map(R.when( | ||
R.is(Object), | ||
omitRecursively(keys) | ||
)), | ||
R.when( | ||
isPlainObject, | ||
R.omit(keys) | ||
) | ||
R.map(R.when(R.is(Object), omitRecursively(keys))), | ||
R.when(isPlainObject, R.omit(keys)) | ||
)(input); | ||
@@ -71,15 +62,16 @@ } | ||
'subtractObject :: Object -> Object -> Object', | ||
R.uncurryN(2, objToSubstract => R.converge( | ||
R.omit, | ||
[ | ||
R.uncurryN(2, objToSubstract => | ||
R.converge(R.omit, [ | ||
R.compose( | ||
R.keys, | ||
R.pickBy(R.both( | ||
(value, key) => R.has(key, objToSubstract), | ||
(value, key) => R.propEq(key, value, objToSubstract) | ||
)) | ||
R.pickBy( | ||
R.both( | ||
(value, key) => R.has(key, objToSubstract), | ||
(value, key) => R.propEq(key, value, objToSubstract) | ||
) | ||
) | ||
), | ||
R.identity, | ||
] | ||
)) | ||
]) | ||
) | ||
); | ||
@@ -101,5 +93,8 @@ | ||
'renameKeys :: Map a b -> Map a c -> Map b c', | ||
(keysMap, obj) => R.reduce( | ||
(acc, key) => R.assoc(keysMap[key] || key, obj[key], acc), {}, R.keys(obj) | ||
) | ||
(keysMap, obj) => | ||
R.reduce( | ||
(acc, key) => R.assoc(keysMap[key] || key, obj[key], acc), | ||
{}, | ||
R.keys(obj) | ||
) | ||
); | ||
@@ -114,10 +109,6 @@ | ||
'reverseLookup :: a -> Map b a -> b', | ||
(val, obj) => R.compose( | ||
R.nth(0), | ||
R.find(R.compose( | ||
R.equals(val), | ||
R.nth(1) | ||
)), | ||
R.toPairs | ||
)(obj) | ||
(val, obj) => | ||
R.compose(R.nth(0), R.find(R.compose(R.equals(val), R.nth(1))), R.toPairs)( | ||
obj | ||
) | ||
); | ||
@@ -131,7 +122,3 @@ | ||
'invertMap :: Map a b -> Map b a', | ||
R.compose( | ||
R.fromPairs, | ||
R.map(R.reverse), | ||
R.toPairs | ||
) | ||
R.compose(R.fromPairs, R.map(R.reverse), R.toPairs) | ||
); |
@@ -11,4 +11,4 @@ import * as R from 'ramda'; | ||
// :: ERROR_CODE -> Error -> Promise.Reject Error | ||
export const rejectWithCode = R.curry( | ||
(code, err) => Promise.reject(Object.assign(err, { errorCode: code })) | ||
export const rejectWithCode = R.curry((code, err) => | ||
Promise.reject(Object.assign(err, { errorCode: code })) | ||
); | ||
@@ -52,9 +52,8 @@ | ||
// :: [Number] -> (b -> Boolean) -> (b -> Error) -> (() -> Promise a b) -> (b -> Promise a b) | ||
export const retryOrFail = R.curry( | ||
(delays, stopFn, errFn, retryFn) => { | ||
const maxRetries = delays.length; | ||
let retryCounter = 0; | ||
export const retryOrFail = R.curry((delays, stopFn, errFn, retryFn) => { | ||
const maxRetries = delays.length; | ||
let retryCounter = 0; | ||
const run = data => new Promise((resolve, reject) => { | ||
const run = data => | ||
new Promise((resolve, reject) => { | ||
if (stopFn(data) || retryCounter === maxRetries) { | ||
@@ -74,4 +73,3 @@ reject(errFn(data)); | ||
return run; | ||
} | ||
); | ||
return run; | ||
}); |
@@ -35,21 +35,13 @@ import * as R from 'ramda'; | ||
// typeUrl :: String -> String -> String | ||
const typeUrl = R.curry( | ||
(docUrl, typeName) => `${docUrl}${typeName}` | ||
); | ||
const typeUrl = R.curry((docUrl, typeName) => `${docUrl}${typeName}`); | ||
// hasType :: Type -> (x -> Boolean) | ||
export const hasType = R.curry( | ||
(type, x) => type.validate(x).isRight | ||
); | ||
export const hasType = R.curry((type, x) => type.validate(x).isRight); | ||
// hasOneOfType :: [Type] -> (x -> Boolean) | ||
export const hasOneOfType = R.curry( | ||
types => R.anyPass( | ||
R.map(hasType, types) | ||
) | ||
); | ||
export const hasOneOfType = R.curry(types => R.anyPass(R.map(hasType, types))); | ||
// NullaryType :: String -> String -> String -> (Any -> Boolean) -> Type | ||
export const NullaryType = R.curry( | ||
(packageName, docUrl, typeName, predicate) => $.NullaryType( | ||
export const NullaryType = R.curry((packageName, docUrl, typeName, predicate) => | ||
$.NullaryType( | ||
qualifiedTypeName(packageName, typeName), | ||
@@ -63,8 +55,9 @@ typeUrl(docUrl, typeName), | ||
export const UnaryType = R.curry( | ||
(packageName, docUrl, typeName, predicate, extractor) => $.UnaryType( | ||
qualifiedTypeName(packageName, typeName), | ||
typeUrl(docUrl, typeName), | ||
predicate, | ||
extractor | ||
) | ||
(packageName, docUrl, typeName, predicate, extractor) => | ||
$.UnaryType( | ||
qualifiedTypeName(packageName, typeName), | ||
typeUrl(docUrl, typeName), | ||
predicate, | ||
extractor | ||
) | ||
); | ||
@@ -75,14 +68,15 @@ | ||
export const BinaryType = R.curry( | ||
(packageName, docUrl, typeName, predicate, extractorA, extractorB) => $.BinaryType( | ||
qualifiedTypeName(packageName, typeName), | ||
typeUrl(docUrl, typeName), | ||
predicate, | ||
extractorA, | ||
extractorB | ||
) | ||
(packageName, docUrl, typeName, predicate, extractorA, extractorB) => | ||
$.BinaryType( | ||
qualifiedTypeName(packageName, typeName), | ||
typeUrl(docUrl, typeName), | ||
predicate, | ||
extractorA, | ||
extractorB | ||
) | ||
); | ||
// EnumType :: String -> String -> String -> [a] -> Type | ||
export const EnumType = R.curry( | ||
(packageName, docUrl, typeName, values) => $.EnumType( | ||
export const EnumType = R.curry((packageName, docUrl, typeName, values) => | ||
$.EnumType( | ||
qualifiedTypeName(packageName, typeName), | ||
@@ -100,4 +94,4 @@ typeUrl(docUrl, typeName), | ||
// Model :: String -> String -> String -> StrMap Type -> Type | ||
export const Model = R.curry( | ||
(packageName, docUrl, typeName, schema) => NullaryType( | ||
export const Model = R.curry((packageName, docUrl, typeName, schema) => | ||
NullaryType( | ||
packageName, | ||
@@ -115,19 +109,9 @@ docUrl, | ||
// OneOfType :: String -> String -> String -> [Type] -> Type | ||
export const OneOfType = R.curry( | ||
(packageName, docUrl, typeName, types) => NullaryType( | ||
packageName, | ||
docUrl, | ||
typeName, | ||
hasOneOfType(types) | ||
) | ||
export const OneOfType = R.curry((packageName, docUrl, typeName, types) => | ||
NullaryType(packageName, docUrl, typeName, hasOneOfType(types)) | ||
); | ||
// AliasType :: String -> String -> String -> Type -> Type | ||
export const AliasType = R.curry( | ||
(packageName, docUrl, typeName, type) => NullaryType( | ||
packageName, | ||
docUrl, | ||
typeName, | ||
hasType(type) | ||
) | ||
export const AliasType = R.curry((packageName, docUrl, typeName, type) => | ||
NullaryType(packageName, docUrl, typeName, hasType(type)) | ||
); | ||
@@ -142,3 +126,4 @@ | ||
export const Map = BinaryType( | ||
pkgName, dUrl, | ||
pkgName, | ||
dUrl, | ||
'Map', | ||
@@ -151,3 +136,4 @@ R.is(Object), | ||
export const Pair = BinaryType( | ||
pkgName, dUrl, | ||
pkgName, | ||
dUrl, | ||
'Pair', | ||
@@ -160,5 +146,6 @@ x => x instanceof Array && x.length === 2, | ||
export const $Promise = NullaryType( | ||
pkgName, dUrl, | ||
pkgName, | ||
dUrl, | ||
'Promise', | ||
x => x instanceof Promise, | ||
x => x instanceof Promise | ||
); | ||
@@ -165,0 +152,0 @@ |
import * as R from 'ramda'; | ||
import { Either } from 'ramda-fantasy'; | ||
export const sanctuaryDefEitherToRamdaFantasyEither = sdEither => ( | ||
sdEither.isLeft | ||
? Either.Left(sdEither.value) | ||
: Either.Right(sdEither.value) | ||
); | ||
export const sanctuaryDefEitherToRamdaFantasyEither = sdEither => | ||
sdEither.isLeft ? Either.Left(sdEither.value) : Either.Right(sdEither.value); | ||
@@ -10,0 +7,0 @@ export const validateSanctuaryType = R.uncurryN(2, SanctuaryType => |
import { assert } from 'chai'; | ||
import { | ||
isAmong, | ||
uniqLists, | ||
swap, | ||
} from '../src/lists'; | ||
import { isAmong, uniqLists, swap } from '../src/lists'; | ||
@@ -27,12 +23,11 @@ describe('lists', () => { | ||
it('returns filtered list with untouched empty lists', () => { | ||
assert.deepEqual( | ||
uniqLists([['a', 'b', 'c'], ['b', 'c', 'd'], [], []]), | ||
[['a', 'b', 'c'], ['d'], [], []] | ||
); | ||
assert.deepEqual(uniqLists([['a', 'b', 'c'], ['b', 'c', 'd'], [], []]), [ | ||
['a', 'b', 'c'], | ||
['d'], | ||
[], | ||
[], | ||
]); | ||
}); | ||
it('returns empty list for empty list', () => { | ||
assert.deepEqual( | ||
uniqLists([]), | ||
[] | ||
); | ||
assert.deepEqual(uniqLists([]), []); | ||
}); | ||
@@ -43,10 +38,16 @@ }); | ||
it('returns swapped list', () => { | ||
assert.deepEqual( | ||
swap(1, 3, ['a', 'b', 'c', 'd', 'e']), | ||
['a', 'd', 'c', 'b', 'e'] | ||
); | ||
assert.deepEqual( | ||
swap(4, 0, ['a', 'b', 'c', 'd', 'e']), | ||
['e', 'b', 'c', 'd', 'a'] | ||
); | ||
assert.deepEqual(swap(1, 3, ['a', 'b', 'c', 'd', 'e']), [ | ||
'a', | ||
'd', | ||
'c', | ||
'b', | ||
'e', | ||
]); | ||
assert.deepEqual(swap(4, 0, ['a', 'b', 'c', 'd', 'e']), [ | ||
'e', | ||
'b', | ||
'c', | ||
'd', | ||
'a', | ||
]); | ||
}); | ||
@@ -53,0 +54,0 @@ it('throws an error if index is out of range', () => { |
@@ -22,30 +22,15 @@ import { assert } from 'chai'; | ||
it('should return Maybe.Just value', () => { | ||
assert.equal( | ||
explode(Maybe.Just(25)), | ||
25 | ||
); | ||
assert.equal(explode(Maybe.Just(25)), 25); | ||
}); | ||
it('should throw error for Maybe.Nothing', () => { | ||
assert.throws( | ||
() => explode(Maybe.Nothing()), | ||
Error | ||
); | ||
assert.throws(() => explode(Maybe.Nothing()), Error); | ||
}); | ||
it('should return Either.Right value', () => { | ||
assert.equal( | ||
explode(Either.Right(25)), | ||
25 | ||
); | ||
assert.equal(explode(Either.Right(25)), 25); | ||
}); | ||
it('should throw error for Either.Left', () => { | ||
assert.throws( | ||
() => explode(Either.Left('err')), | ||
Error, | ||
); | ||
assert.throws(() => explode(Either.Left('err')), Error); | ||
}); | ||
it('should throw error if its not Maybe or Either', () => { | ||
assert.throws( | ||
() => explode(5), | ||
Error | ||
); | ||
assert.throws(() => explode(5), Error); | ||
}); | ||
@@ -55,12 +40,6 @@ }); | ||
it('should return value for Just', () => { | ||
assert.equal( | ||
explodeMaybe('err', Maybe.Just('correct')), | ||
'correct' | ||
); | ||
assert.equal(explodeMaybe('err', Maybe.Just('correct')), 'correct'); | ||
}); | ||
it('should throw an error for Nothing', () => { | ||
assert.throws( | ||
() => explodeMaybe('err', Maybe.Nothing()), | ||
Error | ||
); | ||
assert.throws(() => explodeMaybe('err', Maybe.Nothing()), Error); | ||
}); | ||
@@ -70,12 +49,6 @@ }); | ||
it('should return value for Right', () => { | ||
assert.equal( | ||
explodeEither(Either.Right('correct')), | ||
'correct' | ||
); | ||
assert.equal(explodeEither(Either.Right('correct')), 'correct'); | ||
}); | ||
it('should throw an error for Left', () => { | ||
assert.throws( | ||
() => explodeEither(Either.Left('not correct')), | ||
Error | ||
); | ||
assert.throws(() => explodeEither(Either.Left('not correct')), Error); | ||
}); | ||
@@ -86,12 +59,6 @@ }); | ||
it('should return Left value for Left', () => { | ||
assert.equal( | ||
foldEither(identity, F, Either.Left('left')), | ||
'left' | ||
); | ||
assert.equal(foldEither(identity, F, Either.Left('left')), 'left'); | ||
}); | ||
it('should return Right value for Right', () => { | ||
assert.equal( | ||
foldEither(F, identity, Either.Right('right')), | ||
'right' | ||
); | ||
assert.equal(foldEither(F, identity, Either.Right('right')), 'right'); | ||
}); | ||
@@ -101,6 +68,3 @@ }); | ||
it('should return specified value for Nothing', () => { | ||
assert.equal( | ||
foldMaybe(42, F, Maybe.Nothing()), | ||
42 | ||
); | ||
assert.equal(foldMaybe(42, F, Maybe.Nothing()), 42); | ||
}); | ||
@@ -126,9 +90,7 @@ it('should return a value for Just', () => { | ||
it('returns resolved promise contained Right value', () => | ||
eitherToPromise(Either.Right(52)) | ||
.then(val => assert.equal(val, 52)) | ||
); | ||
eitherToPromise(Either.Right(52)).then(val => assert.equal(val, 52))); | ||
it('returns rejected promise contained Left value', () => | ||
eitherToPromise(Either.Left('err')) | ||
.catch(val => assert.equal(val, 'err')) | ||
); | ||
eitherToPromise(Either.Left('err')).catch(val => | ||
assert.equal(val, 'err') | ||
)); | ||
}); | ||
@@ -142,4 +104,3 @@ | ||
Maybe.Just(52) | ||
).then(val => assert.equal(val, 57)) | ||
); | ||
).then(val => assert.equal(val, 57))); | ||
it('returns rejected promise', () => | ||
@@ -150,7 +111,6 @@ maybeToPromise( | ||
Maybe.Nothing() | ||
).catch((err) => { | ||
).catch(err => { | ||
assert.instanceOf(err, Error); | ||
assert.equal(err.message, 'It is Nothing!'); | ||
}) | ||
); | ||
})); | ||
it('returns rejected promise without nesting', () => | ||
@@ -161,7 +121,6 @@ maybeToPromise( | ||
Maybe.Nothing() | ||
).catch((err) => { | ||
).catch(err => { | ||
assert.instanceOf(err, Error); | ||
assert.equal(err.message, 'It is Nothing!'); | ||
}) | ||
); | ||
})); | ||
}); | ||
@@ -175,16 +134,11 @@ | ||
assert.isTrue(res.isRight); | ||
assert.sameMembers( | ||
explodeEither(res), | ||
['d', 'e', 'a', 'b', 'c'] | ||
); | ||
assert.sameMembers(explodeEither(res), ['d', 'e', 'a', 'b', 'c']); | ||
}); | ||
it('should return Either.Left if iterator returned Either.Left at least one time', () => { | ||
const iterator = (acc, a) => ((a === 'b') ? Either.Left('err') : Either.Right([...acc, a])); | ||
const iterator = (acc, a) => | ||
a === 'b' ? Either.Left('err') : Either.Right([...acc, a]); | ||
const res = reduceEither(iterator, ['d', 'e'], ['a', 'b', 'c']); | ||
assert.isTrue(res.isLeft); | ||
assert.throws( | ||
() => explodeEither(res), | ||
Error | ||
); | ||
assert.throws(() => explodeEither(res), Error); | ||
}); | ||
@@ -199,16 +153,11 @@ }); | ||
assert.isTrue(res.isJust); | ||
assert.sameMembers( | ||
explodeMaybe('err', res), | ||
['d', 'e', 'a', 'b', 'c'] | ||
); | ||
assert.sameMembers(explodeMaybe('err', res), ['d', 'e', 'a', 'b', 'c']); | ||
}); | ||
it('should return Maybe.Nothing if iterator returned Maybe.Nothing at least one time', () => { | ||
const iterator = (acc, a) => ((a === 'b') ? Maybe.Nothing() : Maybe.Just([...acc, a])); | ||
const iterator = (acc, a) => | ||
a === 'b' ? Maybe.Nothing() : Maybe.Just([...acc, a]); | ||
const res = reduceMaybe(iterator, ['d', 'e'], ['a', 'b', 'c']); | ||
assert.isTrue(res.isNothing); | ||
assert.throws( | ||
() => explodeMaybe('err', res), | ||
Error | ||
); | ||
assert.throws(() => explodeMaybe('err', res), Error); | ||
}); | ||
@@ -222,6 +171,3 @@ | ||
assert.equal(res.isRight, true); | ||
assert.equal( | ||
explodeEither(res), | ||
6 | ||
); | ||
assert.equal(explodeEither(res), 6); | ||
}); | ||
@@ -231,6 +177,3 @@ it('returns Either.Left String for falsy condition', () => { | ||
assert.equal(res.isLeft, true); | ||
assert.equal( | ||
foldEither(identity, identity, res), | ||
'3 less than 5' | ||
); | ||
assert.equal(foldEither(identity, identity, res), '3 less than 5'); | ||
}); | ||
@@ -237,0 +180,0 @@ }); |
@@ -59,6 +59,7 @@ import { assert } from 'chai'; | ||
it('omits empty values from object', () => { | ||
assert.hasAllKeys( | ||
omitEmptyValues({ a: 1, b: 2, c: '', d: '', e: 3 }), | ||
['a', 'b', 'e'] | ||
); | ||
assert.hasAllKeys(omitEmptyValues({ a: 1, b: 2, c: '', d: '', e: 3 }), [ | ||
'a', | ||
'b', | ||
'e', | ||
]); | ||
}); | ||
@@ -69,6 +70,6 @@ }); | ||
it('returns subtracted object (if fields are equal)', () => { | ||
assert.deepEqual( | ||
subtractObject({ a: 1, b: 2 }, { a: 1, b: 9, c: 3 }), | ||
{ b: 9, c: 3 } | ||
); | ||
assert.deepEqual(subtractObject({ a: 1, b: 2 }, { a: 1, b: 9, c: 3 }), { | ||
b: 9, | ||
c: 3, | ||
}); | ||
}); | ||
@@ -79,6 +80,6 @@ }); | ||
it('returns object with renamed keys', () => { | ||
assert.deepEqual( | ||
renameKeys({ a: 'b', b: 'c', c: 'd' }, { a: 1, b: 2 }), | ||
{ b: 1, c: 2 } | ||
); | ||
assert.deepEqual(renameKeys({ a: 'b', b: 'c', c: 'd' }, { a: 1, b: 2 }), { | ||
b: 1, | ||
c: 2, | ||
}); | ||
}); | ||
@@ -90,3 +91,9 @@ }); | ||
assert.equal( | ||
reverseLookup('find me', { a: 'a', b: 'b', c: 'find me', d: 'd', e: 'find me' }), | ||
reverseLookup('find me', { | ||
a: 'a', | ||
b: 'b', | ||
c: 'find me', | ||
d: 'd', | ||
e: 'find me', | ||
}), | ||
'c' | ||
@@ -99,8 +106,8 @@ ); | ||
it('returns object with switched keys and values', () => { | ||
assert.deepEqual( | ||
invertMap({ a: 'abc', b: 'bcd' }), | ||
{ abc: 'a', bcd: 'b' } | ||
); | ||
assert.deepEqual(invertMap({ a: 'abc', b: 'bcd' }), { | ||
abc: 'a', | ||
bcd: 'b', | ||
}); | ||
}); | ||
}); | ||
}); |
import R from 'ramda'; | ||
import { assert } from 'chai'; | ||
import { | ||
tapP, | ||
retryOrFail, | ||
} from '../src/promises'; | ||
import { tapP, retryOrFail } from '../src/promises'; | ||
@@ -12,5 +9,6 @@ describe('promises', () => { | ||
it('should return the same value', () => { | ||
const promiseFn = () => new Promise((resolve) => { | ||
setTimeout(() => resolve(true), 5); | ||
}); | ||
const promiseFn = () => | ||
new Promise(resolve => { | ||
setTimeout(() => resolve(true), 5); | ||
}); | ||
@@ -22,10 +20,10 @@ Promise.resolve(1) | ||
it('should pass argument into promiseFn', () => { | ||
const promiseFn = arg => new Promise((resolve) => { | ||
const newValue = arg + 5; | ||
assert.equal(newValue, 6); | ||
setTimeout(() => resolve(newValue), 5); | ||
}); | ||
const promiseFn = arg => | ||
new Promise(resolve => { | ||
const newValue = arg + 5; | ||
assert.equal(newValue, 6); | ||
setTimeout(() => resolve(newValue), 5); | ||
}); | ||
Promise.resolve(1) | ||
.then(tapP(promiseFn)); | ||
Promise.resolve(1).then(tapP(promiseFn)); | ||
}); | ||
@@ -53,13 +51,12 @@ it('should return Promise.reject if inner function return Promise.reject', () => { | ||
return Promise.reject(retriesCount); | ||
}, | ||
} | ||
)(); | ||
return result.then(() => { | ||
assert.fail('got resolved promise', 'expected rejected promise'); | ||
}).catch(() => { | ||
assert.equal( | ||
retriesCount, | ||
retriesSchedule.length | ||
); | ||
}); | ||
return result | ||
.then(() => { | ||
assert.fail('got resolved promise', 'expected rejected promise'); | ||
}) | ||
.catch(() => { | ||
assert.equal(retriesCount, retriesSchedule.length); | ||
}); | ||
}); | ||
@@ -79,10 +76,12 @@ it('should stop retrying if `stopFn` predicate returns true', () => { | ||
return Promise.reject(retriesCount); | ||
}, | ||
} | ||
)(); | ||
return result.then(() => { | ||
assert.fail('got resolved promise', 'expected rejected promise'); | ||
}).catch(() => { | ||
assert.equal(retriesCount, retryToStopOn); | ||
}); | ||
return result | ||
.then(() => { | ||
assert.fail('got resolved promise', 'expected rejected promise'); | ||
}) | ||
.catch(() => { | ||
assert.equal(retriesCount, retryToStopOn); | ||
}); | ||
}); | ||
@@ -95,13 +94,8 @@ it('should stop retrying after a successful try', () => { | ||
const result = retryOrFail( | ||
retriesSchedule, | ||
R.F, | ||
R.identity, | ||
() => { | ||
retriesCount += 1; | ||
return retriesCount === retryToSucceedOn | ||
? Promise.resolve(retriesCount) | ||
: Promise.reject(retriesCount); | ||
}, | ||
)(); | ||
const result = retryOrFail(retriesSchedule, R.F, R.identity, () => { | ||
retriesCount += 1; | ||
return retriesCount === retryToSucceedOn | ||
? Promise.resolve(retriesCount) | ||
: Promise.reject(retriesCount); | ||
})(); | ||
@@ -108,0 +102,0 @@ return result.then(() => { |
@@ -9,6 +9,3 @@ import { assert } from 'chai'; | ||
it('without nested Maps', () => { | ||
const testFn = def( | ||
't :: Map String Number -> [Number]', | ||
R.values | ||
); | ||
const testFn = def('t :: Map String Number -> [Number]', R.values); | ||
const result = testFn({ a: 1, b: 2 }); | ||
@@ -20,6 +17,3 @@ assert.sameMembers(result, [1, 2]); | ||
't :: Map String (Map String Number) -> [[Number]]', | ||
R.compose( | ||
R.map(R.values), | ||
R.values | ||
) | ||
R.compose(R.map(R.values), R.values) | ||
); | ||
@@ -43,3 +37,3 @@ const result = testFn({ a: { b: 0, c: 1 }, d: { e: 2, f: 3 } }); | ||
't :: Pair String (Pair Number Number) -> String', | ||
pair => `${pair[0]}_${(pair[1][0] * pair[1][1])}` | ||
pair => `${pair[0]}_${pair[1][0] * pair[1][1]}` | ||
); | ||
@@ -46,0 +40,0 @@ const result = testFn(['abc', [2, 7]]); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
132231
1657