本文整理汇总了TypeScript中ramda.reduce函数的典型用法代码示例。如果您正苦于以下问题:TypeScript reduce函数的具体用法?TypeScript reduce怎么用?TypeScript reduce使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了reduce函数的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: getAddress
/**
* Return a string of a formatted address
* @param fields The array of address fields
*/
static getAddress(fields: Array<string>): string {
let str = '';
const concat = R.reduce((a, b) => {
if (R.isEmpty(b) || R.isNil(b)) { return a }
return a + '\n' + b
}, '');
return concat(fields);
}
示例2: getAllInDirectory
export function getAllInDirectory (directory: string): Array<string> {
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));
}
示例3: relationExtractor
export function relationExtractor(model): string[] {
let keys = Object.keys(model.tableAttributes);
function modelReducer(acc, key) {
if (!R.isNil(model.tableAttributes[key].references)) {
acc.push(model.tableAttributes[key].references.model);
// references.model here is the name of the table
}
return acc;
}
return R.reduce(modelReducer, [], keys);
};
示例4:
export const sendEmail$ = (applicant) => {
const cc = 'anli@simbiosis.com.sg';
const array = R.reject(R.isNil)([
applicant.hasSps ? 'SPS' : null,
applicant.hasSrp ? 'SRP' : null,
applicant.hasSrpSupervisor ? 'SRP Approved Supervisor' : null,
]);
const applicantText = R.reduce((a, n) => (a === '') ? n : `${a}, ${n}`, '')(array);
const text = `<p>Dear ${applicant.applicantName}</p><p>We have received your ${applicantText} applicant package.</p><p>We will keep you updated on the progress.</p><p>Thank you</p>`;
return this.mailgun.send$(`${applicant.applicantEmail}`, 'Applicant Received', text, cc)
.first()
.catch(err => {
console.log(err);
return Observable.of(err)
})
}
示例5: next
export async function removeSetCookie<T extends IOClients, U, V> (ctx: ServiceContext<T, U, V>, next: () => Promise<any>) {
const { clients: { logger } } = ctx
await next()
const setCookie: string[] | undefined = ctx.response.headers['set-cookie']
if (!setCookie || isEmpty(setCookie)) {
return
}
const cacheControl: string | undefined = ctx.response.headers['cache-control']
const scope = findScopeInCacheControl(cacheControl)
if (scope === 'public') {
const indexedCookies = indexCookieByKeys(setCookie)
const cookies = reduce(
(acc, [key, payload]) => {
if (BLACKLISTED_COOKIES.has(key)) {
acc.droppedKeys.push(key)
} else {
acc.addedPayload.push(payload)
}
return acc
},
{
addedPayload: [],
droppedKeys: [],
} as CookieAccumulator,
indexedCookies
)
if (cookies.droppedKeys.length > 0) {
ctx.set('set-cookie', cookies.addedPayload)
console.warn(warnMessage(cookies.droppedKeys))
logger.warn({
cookieKeys: cookies.droppedKeys,
message: 'Setting cookies in a public route!',
}).catch()
}
}
}
示例6: put
const isSysAdmin = !!R.find(role => role.name === 'SYS_ADMIN')(currentRoles);
logger.debug('[init]', 'current user isSysAdmin', isSysAdmin);
const authoritiesList = R.compose(
// remove null values
R.filter(R.identity),
// 后端返回字符串时需要反序列化为 JSON
R.map(role => {
const each = R.prop('authorities')(role);
return R.is(String, each) ? JSON.parse(each) : each;
}),
)(currentRoles);
logger.debug('[init]', 'current authoritiesList is', authoritiesList);
const authorities = R.reduce(R.mergeWith(R.or), {})(authoritiesList);
logger.debug('[init]', 'current authorities is', authorities);
const menus = yield menuProxy.init(isSysAdmin, authorities);
logger.log('[init]', 'init sage, menus is', menus);
yield put({ type: menuActionTypes.INIT_SUCCESS, payload: { menus } });
} else {
logger.warn('[init]', 'cannot found any roles');
}
} else {
logger.warn('[init]', 'cannot found current user');
}
} catch (e) {
logger.error('[init]', e);
}
示例7: UpdatesState
webHookUpdates.map((updates: TcombUpdate[]) => UpdatesState({
startDate: initialState.startDate,
offset: reduce(max('update_id'), 0, updates) + 1,
updates
})))
示例8: typeof
if (device === null) {
return result;
}
if (isDisk(device)) {
return { ...result, [key]: `disk-${device.disk_id}` };
}
if (isVolume(device)) {
return { ...result, [key]: `volume-${device.volume_id}` };
}
return result;
};
const isDisk = (
device: Linode.DiskDevice | Linode.VolumeDevice
): device is Linode.DiskDevice => {
return typeof (device as Linode.DiskDevice).disk_id === 'number';
};
const isVolume = (
device: Linode.DiskDevice | Linode.VolumeDevice
): device is Linode.VolumeDevice => {
return typeof (device as Linode.VolumeDevice).volume_id === 'number';
};
export default compose(
reduce(rdx, {}),
toPairs
);
示例9: reduce
const reduceEntries = <T>(fn: (T, any) => T, acc: T) => obj => reduce(fn, acc, Object.entries(obj));