本文整理汇总了TypeScript中ramda.cond函数的典型用法代码示例。如果您正苦于以下问题:TypeScript cond函数的具体用法?TypeScript cond怎么用?TypeScript cond使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了cond函数的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: cond
const swaggerToJoiType = (type: string): string =>
cond([
[equals('token'), always('string')],
[equals('integer'), always('number')],
[equals('int64'), always('integer')],
[T, _type => '' + _type]
])(type);
示例2: isAdmin
export const getAccessMap = (additionalChecks = []) => (ctx: Koa.Context): Function =>
R.cond([
[R.equals('role:admin'), () => isAdmin(ctx)],
[R.equals('role:user'), () => isUser(ctx)],
...additionalChecks,
[R.T, R.F]
]);
示例3: async
}: formatOptions) => async (key: string, value) => {
return await cond([
[readOnly.includes, async () => Maybe.Nothing()],
[encrypted.includes, async () => Maybe.Just(encryptValue(value))],
[salted.includes, async () => Maybe.Just(await bHash(value))],
[hmac.includes, async () => Maybe.Just(await getHmac(value))]
])(key);
};
示例4: cond
export const getProblemFromStatus = status => {
return cond([
[isNil, always(UNKNOWN_ERROR)],
[in200s, always(NONE)],
[in400s, always(CLIENT_ERROR)],
[in500s, always(SERVER_ERROR)],
[T, always(UNKNOWN_ERROR)],
])(status)
}
示例5: upToConditional
static upToConditional(n) {
const isModuloOf = mod => i => i % mod === 0;
const fb = R.cond([
[isModuloOf(15), R.always('fizzbuzz')],
[isModuloOf(5), R.always('buzz')],
[isModuloOf(3), R.always('fizz')],
[R.T, i => '' + i]
]);
return R.map(fb, R.range(1, R.inc(n)));
}
示例6: cond
const isAmex = (card: string) =>
card.length === 15 &&
(card.substr(0, 2) === '34' || card.substr(0, 2) === '37')
const isDiscover = (card: string) =>
card.length === 16 && card.substr(0, 4) === '6011'
const isMasterCard = (card: string) =>
card.length === 16 &&
(card.substr(0, 2) === '51' || card.substr(0, 2) === '55')
const isVisa = (card: string) =>
(card.length === 13 || card.length === 16) && card.substr(0, 1) === '4'
const determineCardType = cond([
[isVisa, always('VISA')],
[isMasterCard, always('MasterCard')],
[isDiscover, always('Discover')],
[isAmex, always('AMEX')],
[T, always('Unknown')]
])
export const luhn = (card: string): boolean => {
let b = 0
let c = 0
let total = 0
let e = 0
// tslint:disable-next-line:whitespace
for (total = +card[(b = card.length - 1)], e = 0; b--; ) {
c = +card[b]
total += ++e % 2 ? (2 * c) % 10 + (c > 4 ? 1 : 0) : c
}
示例7: bonusFn
import {add, cond, drop, equals, head, length, lte, nth, sum, T, take} from 'ramda'
const bonus = rolls => bonusFn(rolls);
const isStrike = rolls => equals(10, head(rolls));
const isSpare = rolls => equals(10, sum(take(2, rolls)));
const bonusFn = cond([
[rolls => lte(length(rolls), 3), () => 0],
[isStrike, rolls => add(add(nth(1, rolls), nth(2, rolls)), bonus(drop(1, rolls)))],
[isSpare, rolls => nth(2, rolls) + bonus(drop(2, rolls))],
[T, rolls => bonus(drop(2, rolls))],
]);
export const score = (rolls: any = []) => {
return sum(rolls) + bonus(rolls)
};
示例8: isByLinode
const isDeprecated = (i: Linode.Image) => i.deprecated === true;
const isRecommended = (i: Linode.Image) => isByLinode(i) && !isDeprecated(i);
const isOlderImage = (i: Linode.Image) => isByLinode(i) && isDeprecated(i);
interface GroupedImages {
deleted?: Linode.Image[];
recommended?: Linode.Image[];
older?: Linode.Image[];
images?: Linode.Image[];
}
export let groupImages: (i: Linode.Image[]) => GroupedImages;
groupImages = groupBy(
cond([
[isRecentlyDeleted, always('deleted')],
[isRecommended, always('recommended')],
[isOlderImage, always('older')],
[(i: Linode.Image) => true, always('images')]
])
);
export const groupNameMap = {
_default: 'Other',
deleted: 'Recently Deleted Disks',
recommended: '64-bit Distributions - Recommended',
older: 'Older Distributions',
images: 'Images'
};
export const getDisplayNameForGroup = (key: string) =>
propOr('Other', key, groupNameMap);
示例9:
(acc, key) =>
R.cond([
[R.equals('options'), R.always(acc)],
[R.equals('get'), key => R.concat(acc, [key, 'head'])],
[R.T, R.concat(acc)]
])(key),