当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript ramda.cond函数代码示例

本文整理汇总了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);
开发者ID:benjambles,项目名称:my-own-world,代码行数:7,代码来源:swagger-to-joi-type.ts

示例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]
    ]);
开发者ID:benjambles,项目名称:my-own-world,代码行数:7,代码来源:index.ts

示例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);
};
开发者ID:benjambles,项目名称:my-own-world,代码行数:8,代码来源:get-formatted-data.ts

示例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)
}
开发者ID:skellock,项目名称:apisauce,代码行数:9,代码来源:apisauce.ts

示例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)));
	}
开发者ID:sprengerjo,项目名称:katas_js,代码行数:11,代码来源:fizzbuzz.ts

示例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
  }
开发者ID:jamespepplinkhouse,项目名称:creditcardchecker-node,代码行数:30,代码来源:credit_cards.ts

示例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)
};
开发者ID:sprengerjo,项目名称:katas_js,代码行数:17,代码来源:bowling_score_calculator.ts

示例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);
开发者ID:linode,项目名称:manager,代码行数:31,代码来源:images.ts

示例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),
开发者ID:benjambles,项目名称:my-own-world,代码行数:6,代码来源:index.ts


注:本文中的ramda.cond函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。