本文整理汇总了TypeScript中lodash.curry函数的典型用法代码示例。如果您正苦于以下问题:TypeScript curry函数的具体用法?TypeScript curry怎么用?TypeScript curry使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了curry函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: metricFindQuery
metricFindQuery(query) {
var interpolated = this.templateSrv.replace(query, null, 'regex');
return this._seriesQuery(interpolated)
.then(_.curry(this.responseParser.parse)(query));
}
示例2: mapInternal
) {
const entries = await mapInternal(
async (value: T, index: number, collection: T[]) => {
return [await iteratee(value, index, collection), value] as [boolean, T];
},
concurrency,
collection,
);
return entries.filter(([valid]) => valid).map(([, value]) => value);
}
export interface FilterConcurrent {
<T>(iteratee: Iterator<T, boolean>, concurrency: number, collection: PromiseOrValue<T[]>): Promise<T[]>;
<T>(iteratee: Iterator<T, boolean>, concurrency: number): CurriedFunction1<PromiseOrValue<T[]>, Promise<T[]>>;
<T>(iteratee: Iterator<T, boolean>): CurriedFunction2<number, PromiseOrValue<T[]>, Promise<T[]>>;
<T>(): CurriedFunction3<Iterator<T, boolean>, number, PromiseOrValue<T[]>, Promise<T[]>>;
}
export const filterConcurrent: FilterConcurrent = curry(filterInternal);
export interface Filter {
<T>(iteratee: Iterator<T, boolean>, collection: PromiseOrValue<T[]>): Promise<boolean>;
<T>(iteratee: Iterator<T, boolean>): CurriedFunction1<PromiseOrValue<T[]>, Promise<boolean>>;
<T>(): CurriedFunction2<Iterator<T, boolean>, PromiseOrValue<T[]>, Promise<boolean>>;
}
export const filter: Filter = bind(filterInternal, null, bind.placeholder, Infinity, bind.placeholder) as any;
export const filterSeries: Filter = bind(filterInternal, null, bind.placeholder, 1, bind.placeholder) as any;
示例3: removePreAndSuf
export function removePreAndSuf(value: string, prefix: string, suffix: string): string {
return _.flow([_.curry(removeSuffix)(_, suffix), _.curry(removePrefix)(_, prefix)])(value);
}
示例4: mapInternal
import { mapInternal } from './map';
async function someInternal<T>(
iteratee: Iterator<T, boolean>,
concurrency: number,
collection: PromiseOrValue<T[]>,
) {
const entries = await mapInternal(iteratee, concurrency, collection);
return entries.some(identity);
}
export interface SomeConcurrent {
<T>(iteratee: Iterator<T, boolean>, concurrency: number, collection: PromiseOrValue<T[]>): Promise<boolean>;
<T>(iteratee: Iterator<T, boolean>, concurrency: number): CurriedFunction1<PromiseOrValue<T[]>, Promise<boolean>>;
<T>(iteratee: Iterator<T, boolean>): CurriedFunction2<number, PromiseOrValue<T[]>, Promise<boolean>>;
<T>(): CurriedFunction3<Iterator<T, boolean>, number, PromiseOrValue<T[]>, Promise<boolean>>;
}
export const someConcurrent: SomeConcurrent = curry(someInternal);
export interface Some {
<T>(iteratee: Iterator<T, boolean>, collection: PromiseOrValue<T[]>): Promise<boolean>;
<T>(iteratee: Iterator<T, boolean>): CurriedFunction1<PromiseOrValue<T[]>, Promise<boolean>>;
<T>(): CurriedFunction2<Iterator<T, boolean>, PromiseOrValue<T[]>, Promise<boolean>>;
}
export const some: Some = bind(someInternal, null, bind.placeholder, Infinity, bind.placeholder) as any;
export const someSeries: Some = bind(someInternal, null, bind.placeholder, 1, bind.placeholder) as any;
示例5: return
import { curry, CurriedFunction1, CurriedFunction2, CurriedFunction3 } from 'lodash';
import { Reducer, PromiseOrValue } from './utils/common';
export async function reduceRightInternal<T, U>(
iteratee: Reducer<T, U>,
initialValue: PromiseOrValue<U>,
collection: PromiseOrValue<T[]>,
) {
return (await collection).reduceRight<Promise<U>>(
async (prevValue, value, currentIndex, array) => {
return await iteratee(await prevValue, value, currentIndex, array);
},
Promise.resolve(initialValue),
);
}
export interface ReduceRight {
<T, U>(iteratee: Reducer<T, U>, initialValue: PromiseOrValue<U>, collection: PromiseOrValue<T[]>): Promise<boolean>;
<T, U>(iteratee: Reducer<T, U>, initialValue: PromiseOrValue<U>): CurriedFunction1<PromiseOrValue<T[]>, Promise<boolean>>;
<T, U>(iteratee: Reducer<T, U>): CurriedFunction2<PromiseOrValue<U>, PromiseOrValue<T[]>, Promise<boolean>>;
<T, U>(): CurriedFunction3<Reducer<T, U>, PromiseOrValue<U>, PromiseOrValue<T[]>, Promise<boolean>>;
}
export const reduceRight: ReduceRight = curry(reduceRightInternal);
示例6: curry
const mapReducer = action => curry(getReducer(action.type))(action);
示例7: return
import { curry, CurriedFunction1, CurriedFunction2, CurriedFunction3 } from 'lodash';
import { Reducer, PromiseOrValue } from './utils/common';
export async function reduceInternal<T, U>(
iteratee: Reducer<T, U>,
initialValue: PromiseOrValue<U>,
collection: PromiseOrValue<T[]>,
) {
return (await collection).reduce<Promise<U>>(
async (prevValue, value, currentIndex, array) => {
return await iteratee(await prevValue, value, currentIndex, array);
},
Promise.resolve(initialValue),
);
}
export interface Reduce {
<T, U>(iteratee: Reducer<T, U>, initialValue: PromiseOrValue<U>, collection: PromiseOrValue<T[]>): Promise<boolean>;
<T, U>(iteratee: Reducer<T, U>, initialValue: PromiseOrValue<U>): CurriedFunction1<PromiseOrValue<T[]>, Promise<boolean>>;
<T, U>(iteratee: Reducer<T, U>): CurriedFunction2<PromiseOrValue<U>, PromiseOrValue<T[]>, Promise<boolean>>;
<T, U>(): CurriedFunction3<Reducer<T, U>, PromiseOrValue<U>, PromiseOrValue<T[]>, Promise<boolean>>;
}
export const reduce: Reduce = curry(reduceInternal);
示例8: initialAction
export async function initialAction(state: State) {
console.log("First!");
return state;
}
export function githubInitialized(text: string) {
let [token, repo, branch] = text.split(' ');
Actions.onNext(initializeGitHub(repo, token, branch));
};
const initializeGitHub = curry(
async (repo: string, token: string, branch: string, state: State) => {
let github = state.github || new GitHubHelper();
await github.setup(token, repo, branch);
let message = "Logged in";
let files = new Map(), changes = new Map();
return { changes, files, github, message };
}
);
export function filesListed() { Actions.onNext(listFiles); }
async function listFiles(state: State) {
let {github} = state;
let entries = await github.listFiles();
let files = new Map<string, string>();
for (let e of entries) {
files.set(e.path, await github.download(e.download_url));
}
return Object.assign({}, state, { files });
示例9: curry
const curriedReducer = actionType => curry(this[camelCase(actionType)]);
示例10: functionChanged
import { Subject } from 'rx';
import { curry } from 'lodash';
import { State } from './State';
export interface Action { (state: State): State };
export const Actions = new Subject<Action | State>();
export function functionChanged(fn, value) {
Actions.onNext(changeFunction(fn, value));
}
export const changeFunction = curry((fn: string, value: any, state: State): State => {
return Object.assign({}, state, { [fn]: value });
});
export function dataChanged(name, value, data) {
Actions.onNext(changeData(name, value, data));
}
export const changeData = curry((name: string, value: any, data, state: State): State => {
return Object.assign({}, state, { [name]: value, data: data });
});