當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript ramda.curry函數代碼示例

本文整理匯總了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;未經允許,請勿轉載。