當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。