• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript ramda.curry函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了TypeScript中ramda.curry函数的典型用法代码示例。如果您正苦于以下问题:TypeScript curry函数的具体用法?TypeScript curry怎么用?TypeScript curry使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了curry函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。

示例1: return

export function promisify<T>(f: Function): (...args: any[]) => Promise<T> {
  return (...args: any[]) =>
    new Promise<T>((resolve, reject) => f(...args, (err: any, data: T) => {
      if (err) {
        reject(err);
      } else {
        resolve(data);
      }
    }));
}

const log = R.curry(
  (msg?: string, data?: any) => {
    if (msg) {
      console.log(msg, data);
    } else {
      console.log(data);
    }
    return data;
  }
);

const glob = R.curry(
  (pattern: string, path: string) =>
    promisify<string[]>(_glob)(pattern, { root: path })
);

const mv = promisify<void>(_mv);

const inName = R.curry((patterns: string[], file: string) => {
  const { name } = path.parse(file);
  return R.contains(name, patterns);
开发者ID:aleung,项目名称:jekyll-to-gitbook,代码行数:32,代码来源:index.ts


示例2: domify

import * as R from 'ramda'
import domify from '../domify/domify'

const splitBySelector = (
    {
        selector,
        onlyChildren = false
    }: { selector: string; onlyChildren?: boolean },
    markup: string
) => {
    const rootNode = domify(markup)

    const markups = onlyChildren
        ? Array.from(rootNode.children)
              .filter(node => node.matches(selector))
              .map(node => node.innerHTML)
        : Array.from(rootNode.querySelectorAll(selector)).map(
              node => node.innerHTML
          )

    return markups
}

export default R.curry(splitBySelector)
开发者ID:yakhinvadim,项目名称:longman-to-anki,代码行数:24,代码来源:splitBySelector.ts


示例3: switch

  entityID: string | number
) => {
  if (!entityType || !entityID) {
    return;
  }
  const _store = store.getState();
  const {
    linodes,
    domains,
    nodeBalancers,
    images,
    volumes
  } = _store.__resources;
  switch (entityType) {
    case 'linode':
      return linodes.entities.find(linode => entityID === linode.id);
    case 'image':
      return images.entities.find(image => entityID === image.id);
    case 'nodebalancer':
      return nodeBalancers.itemsById[entityID];
    case 'domain':
      return domains.entities.find(domain => entityID === domain.id);
    case 'volume':
      return volumes.itemsById[entityID];
    default:
      return;
  }
};

export const getEntityByIDFromStore = curry(_getEntityByIDFromStore);
开发者ID:linode,项目名称:manager,代码行数:30,代码来源:getEntityByIDFromStore.ts


示例4: urlQueryParser

  .forEach((key) => {
    query.attributes[key] = raw[key];
  });

  Object.keys(raw).filter((key) => {
    return !R.isNil(model.options.scopes[key]);
  })
  .forEach((key) => {
    query.scope = key;
  });

  let pagination = ['limit', 'offset', 'order'];

  pagination.filter((key) => {
    // throw raw[key];
    return !R.isNil(raw[key]);
  })
  .forEach((key) => {
    if (key === 'order' && !Array.isArray(raw[key])) {
      raw[key] = [raw[key]];
    }
    query.pagination[key] = raw[key];
  });

  return query;
};

export default R.curry(function(relationSchema, model, query) {
  return urlQueryParser(relationSchema, model, query);
});
开发者ID:repositive,项目名称:hapi-path-generator,代码行数:30,代码来源:httpQueryParser.ts


示例5: curry

import Rx from 'rxjs';
import {
  curry
} from 'ramda';

const listen = curry((event: string, element: HTMLElement) => {
  return Rx.Observable.fromEvent(element, event);
});

const subscribe = curry((success, error, stream) => {
  stream.subscribe(success, error);
});

export {
  listen,
  subscribe
};
开发者ID:markj-,项目名称:hardcore-functional-todo,代码行数:17,代码来源:streams.ts


示例6: merge


//.........这里部分代码省略.........
          await transform(axiosRequestConfig)
        }
      }
    }

    // after the call, convert the axios response, then execute our monitors
    const chain = pipe(
      convertResponse(toNumber(new Date())),
      // partial(convertResponse, [toNumber(new Date())]),
      runMonitors,
    )

    return instance
      .request(axiosRequestConfig)
      .then(chain)
      .catch(chain)
  }

  /**
   * Fires after we convert from axios' response into our response.  Exceptions
   * raised for each monitor will be ignored.
   */
  const runMonitors = ourResponse => {
    monitors.forEach(monitor => {
      try {
        monitor(ourResponse)
      } catch (error) {
        // all monitor complaints will be ignored
      }
    })
    return ourResponse
  }

  /**
   * Converts an axios response/error into our response.
   */
  const convertResponse = curry((startedAt: number, axiosResult: AxiosResponse | AxiosError) => {
    const end: number = toNumber(new Date())
    const duration: number = end - startedAt

    // new in Axios 0.13 -- some data could be buried 1 level now
    const isError = axiosResult instanceof Error || axios.isCancel(axiosResult)
    const axiosResponse = axiosResult as AxiosResponse
    const axiosError = axiosResult as AxiosError
    const response = isError ? axiosError.response : axiosResponse
    const status = (response && response.status) || null
    const problem = isError ? getProblemFromError(axiosResult) : getProblemFromStatus(status)
    const originalError = isError ? axiosError : null
    const ok = in200s(status)
    const config = axiosResult.config || null
    const headers = (response && response.headers) || null
    let data = (response && response.data) || null

    // give an opportunity for anything to the response transforms to change stuff along the way
    let transformedResponse = {
      duration,
      problem,
      originalError,
      ok,
      status,
      headers,
      config,
      data,
    }
    if (responseTransforms.length > 0) {
      forEach(transform => transform(transformedResponse), responseTransforms)
    }

    return transformedResponse
  })

  // create the base object
  const sauce = {
    axiosInstance: instance,
    monitors,
    addMonitor,
    requestTransforms,
    asyncRequestTransforms,
    responseTransforms,
    addRequestTransform,
    addAsyncRequestTransform,
    addResponseTransform,
    setHeader,
    setHeaders,
    deleteHeader,
    headers,
    setBaseURL,
    getBaseURL,
    get: partial(doRequestWithoutBody, ['get']),
    delete: partial(doRequestWithoutBody, ['delete']),
    head: partial(doRequestWithoutBody, ['head']),
    post: partial(doRequestWithBody, ['post']),
    put: partial(doRequestWithBody, ['put']),
    patch: partial(doRequestWithBody, ['patch']),
    link: partial(doRequestWithoutBody, ['link']),
    unlink: partial(doRequestWithoutBody, ['unlink']),
  }
  // send back the sauce
  return sauce
}
开发者ID:skellock,项目名称:apisauce,代码行数:101,代码来源:apisauce.ts


示例7: curry

import { compose, curry, defaultTo, isEmpty, not, when } from 'ramda';

export default curry((defaultValue: number, v?: null | string | number) =>
  compose<
    string | number | null | undefined,
    number | null | undefined,
    number>(
      defaultTo(defaultValue),
      when(compose(not, isEmpty), (value: string) => +value),
  )(v));
开发者ID:displague,项目名称:manager,代码行数:10,代码来源:defaultNumeric.ts


示例8: normalize

}

const replaceBrackets = (str: string) => str.replace(/[{[<]/g, '(').replace(/[}\]>]/g, ')');
const replaceOperators = (str: string) =>
  str
    .replace(/[|/]/g, OPERATORS.or)
    .replace(/[;&]/g, OPERATORS.and)
    .replace(/ plus /g, OPERATORS.and)
    .replace(OPERATORS_REGEX, R.toLower);

export const normalize = R.pipe(
  removeSpaceFromModule,
  fixOperatorTypos,
  insertPostFixAsStandalone,
  convertCommas,
  R.curry(convertToNumerals)(1),
  replaceBrackets,
  fixBrackets,
  replaceOperators,
  removeModuleTitles,
);

export default function normalizeString(string: string, moduleCode: ModuleCode): string {
  // remove own module code from string (e.g. `CS1000R` would remove `CS1000R`, `CS1000`)
  // @ts-ignore Strings are lists, damn it
  const moduleWithoutPostfix = moduleCode.slice(0, R.findLastIndex(R.test(/\d/), moduleCode) + 1);
  const moduleRegex = new RegExp(`\\b${moduleWithoutPostfix}(?:[A-Z]|[A-Z]R)?\\b`, 'g');
  const preprocessed = string.replace(moduleRegex, '');
  return normalize(preprocessed);
}
开发者ID:nusmodifications,项目名称:nusmods,代码行数:30,代码来源:normalizeString.ts


示例9:

import _ from 'ramda';

export default _.curry((selector: string, html: string) => {
  return document.querySelector(selector).innerHTML = html;
});
开发者ID:markj-,项目名称:hardcore-functional,代码行数:5,代码来源:set-html.ts


示例10: while

import { curryN, curry } from 'ramda';

export const range = (from: number, to: number) => {
  const result = [];
  let n = from - 1;
  while (++n < to) result.push(n);
  return result;
};

export const clamp = curry((min: number, max: number, value: number) => {
  return Math.max(min, Math.min(max, value));
});

export const clampLoop = curry((min: number, max: number, value: number) => {
  const len = Math.abs(max - min);
  let a = value % len;
  if (a > max) a -= len;
  else if (a < min) a += len;
  return a;
});

export const absDiff = (a: number, b: number) => Math.abs(b - a);

export const normalize = curry((a: number, b: number, x: number) => (x - Math.min(a, b)) / absDiff(a, b));

export const mapToRange = curry((a: number, b: number, c: number, d: number, x: number) => {
  const r = (d - c) / (b - a);
  return (x - a) * r + c;
});
开发者ID:alexeden,项目名称:dotstar-node,代码行数:29,代码来源:utils.ts



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript ramda.curryN函数代码示例发布时间:2022-05-25
下一篇:
TypeScript ramda.contains函数代码示例发布时间:2022-05-25
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap