com-tools
Version:
com-tools 提供了一些通用的工具函数;
88 lines (41 loc) • 1.53 kB
Markdown
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home](./index.md) > [com-tools](./com-tools.md) > [safelyIterate](./com-tools.safelyiterate.md)
## safelyIterate() function
safelyIterate(iterable,operation, thisValue) 对 iterable 进行安全的迭代;与 for...of 的区别是:safelyIterate 能保证会迭代过程不会受 operation 中的行为的影响从而迭代每一个元素;
**Signature:**
```typescript
export function safelyIterate<T,ThisValue>(iterable:Iterable<T>,operation:(this:ThisValue,currentValue:T,currentIndex:number,iterable:Iterable<T>)=>any, thisValue?:ThisValue):T[];
```
## Parameters
<table><thead><tr><th>
Parameter
</th><th>
Type
</th><th>
Description
</th></tr></thead>
<tbody><tr><td>
iterable
</td><td>
Iterable<T>
</td><td>
: Iterable 必选; 可迭代的对象;
</td></tr>
<tr><td>
operation
</td><td>
(this:ThisValue,currentValue:T,currentIndex:number,iterable:Iterable<T>)=>any
</td><td>
: (currentValue,currentIndex,iterable)=<!-- -->><!-- -->boolean \| undefined 执行的操作, 该函数的返回值表示是否要过滤出该元素
</td></tr>
<tr><td>
thisValue
</td><td>
ThisValue
</td><td>
_(Optional)_ ? : any 可选,默认值是 iterable ;操作 operation 的 this 值
</td></tr>
</tbody></table>
**Returns:**
T\[\]
boolean \| undefined 表示是否要过滤出 currentValue ;