提交 ce5468ff 编写于 作者: 杜庆泉's avatar 杜庆泉

Update iterable.md

上级 6ff48864
...@@ -244,7 +244,7 @@ class TestClass implements UTSValueIterable<any | null> { ...@@ -244,7 +244,7 @@ class TestClass implements UTSValueIterable<any | null> {
return obj return obj
} }
} }
``` ```
执行结果: 执行结果:
...@@ -268,28 +268,30 @@ item null ...@@ -268,28 +268,30 @@ item null
```typescript ```typescript
class TestClass implements UTSValueIterable<any> { class TestClass implements UTSValueIterable<any | null> {
holderArray: (any | null)[] = [11, 22, null, 33, 44, null] holderArray: (any | null)[] = [11, 22, null, 33, 44, null]
valueIterator(): UTSIterator<any> { valueIterator(): UTSIterator<any | null> {
let holderIndex = 0; let holderIndex = 0;
let arr = this.holderArray.filter((value) => { let arr = this.holderArray.filter((value) => {
return value != null return value != null
}) })
let obj: UTSIterator<any> = { let obj: UTSIterator<any | null> = {
next: () : UTSIteratorResult<any> => {
next: () : UTSIteratorResult<any | null> => {
const done = holderIndex == arr.length const done = holderIndex == arr.length
return { return {
done, done,
value: done ? null : arr[holderIndex++], value: done ? null : arr[holderIndex++],
} as UTSIteratorResult<any> } as UTSIteratorResult<any | null>
} }
} }
return obj return obj
} }
}
}
``` ```
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册