本文整理匯總了TypeScript中ramda.append函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript append函數的具體用法?TypeScript append怎麽用?TypeScript append使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了append函數的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: append
indexedData.forEach((obj: IOMessage, index: number) => {
const length = lengths[index]
if (sumLength + length > MAX_QUERYSTRING_LENGTH) {
batchedData = append(batch, batchedData)
batch = [obj]
sumLength = length
} else {
sumLength = sumLength + length
batch = append(obj, batch)
}
})
示例2: append
export default <T extends { id: string | number }>(item: T, items: T[]) => {
if (items.length === 0) {
return [item];
}
const found = items.findIndex((i) => i.id === item.id);
if (found < 0) {
return append(item, items);
};
return update(found, item, items);
}
示例3: reduce
return reduce((files: string[], file: string) => {
const abspath = join(directory, file);
if (isFile(abspath))
return append(file, files);
if (isDirectory(abspath))
return concat(files,
getAllInDirectory(abspath).map((f: string) => join(relative(directory, abspath), f)));
return files;
}, [], fs.readdirSync(directory));
示例4: require
const fs = require('fs');
const {join: pjoin} = require('path');
const request = require('request');
const Task = require('data.task');
const {map, toUpper, compose, prop, append, traverse} = require('ramda');
const filePath = (file:string):string => (pjoin(__dirname, '../', file));
const logErr = (err):void => console.log(`Error: ${err}`);
const logData = (data):void => console.log('Data', data);
const exists = (x):boolean => x != null;
const taskifyReadFile = (path:string) => {
return new Task((reject, resolve) => {
fs.readFile(path, 'utf8', (err, data) => exists(err) ? reject(err) : resolve(data));
});
};
const taskifyReq = (url:string) => {
return new Task((reject, resolve) => {
request(url, (err, resp, body) => {
exists(err) ? reject(err) : resolve(JSON.parse(body));
});
});
};
const getFilesAsTasks = compose(map(taskifyReadFile), map(filePath));
const files = getFilesAsTasks(['a.txt', 'b.txt', 'c.txt']);
const getSkywalker = map(prop('name'), taskifyReq('http://swapi.co/api/people/1'));
const done = traverse(Task.of, map(toUpper), append(getSkywalker, files));
done.fork(logErr, logData);