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

Update iterable.md

上级 6ff48864
...@@ -226,25 +226,25 @@ for (item of test) { ...@@ -226,25 +226,25 @@ for (item of test) {
```typescript ```typescript
class TestClass implements UTSValueIterable<any | null> { 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 | null> { valueIterator(): UTSIterator<any | null> {
let holderIndex = 0; let holderIndex = 0;
let obj: UTSIterator<any | null> = { let obj: UTSIterator<any | null> = {
next: () : UTSIteratorResult<any | null> => { next: () : UTSIteratorResult<any | null> => {
const done = holderIndex == this.holderArray.length const done = holderIndex == this.holderArray.length
return { return {
done, done,
value: done ? null : this.holderArray[holderIndex++], value: done ? null : this.holderArray[holderIndex++],
} as UTSIteratorResult<any | null> } as UTSIteratorResult<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> => {
const done = holderIndex == arr.length next: () : UTSIteratorResult<any | null> => {
return { const done = holderIndex == arr.length
done, return {
value: done ? null : arr[holderIndex++], done,
} as UTSIteratorResult<any> value: done ? null : arr[holderIndex++],
} 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.
先完成此消息的编辑!
想要评论请 注册