本文整理汇总了TypeScript中underscore.iteratee函数的典型用法代码示例。如果您正苦于以下问题:TypeScript iteratee函数的具体用法?TypeScript iteratee怎么用?TypeScript iteratee使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了iteratee函数的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: fn
export function sum<T>(list: T[], summer: _.ListIterator<T, number>): number {
const fn = _.iteratee(summer) as _.ListIterator<T, number>;
return _.reduce(
list,
(memo, val, index) => {
return memo + fn(val, index, list);
},
0
);
}
示例2: getItemAcrossStores
/**
* Find an item among all stores that matches the params provided.
*/
function getItemAcrossStores(params: { id?: string; hash?: number; notransfer?: boolean }) {
const predicate = _.iteratee(_.pick(params, 'id', 'hash', 'notransfer')) as (DimItem) => boolean;
for (const store of _stores) {
const result = store.items.find(predicate);
if (result) {
return result;
}
}
return undefined;
}
示例3: sum
export function count<T>(list: T[], predicate: _.ListIterator<T, any>): number {
const fn = _.iteratee(predicate) as _.ListIterator<T, any>;
return sum(list, (item, index) => {
return fn(item, index, list) ? 1 : 0;
});
}
示例4: pick
import * as _ from 'underscore'
export const ModelMixin = {
pick( ...args : any[] ){
return _.pick( this, args );
},
escape( attr ){
return _.escape( this[ attr ] );
},
matches( attrs ){
return !!_.iteratee( attrs, this )( this );
},
omit( ...keys : string[] ) : {} {
return this.mapObject( ( value, key ) => {
if( keys.indexOf( key ) < 0 ){
return value;
}
});
},
invert(){
const inverted = {};
this.each( ( value, key ) => inverted[ value ] = key );
return inverted;
},
pairs(){
return this.map( ( value, key ) => [ key, value ] );