Skip to content

Commit c165fa6

Browse files
committed
Update iterators example
1 parent 64ce4cd commit c165fa6

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed
Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,22 @@
11
package cctest
22

33
abstract class Iterator[T]:
4-
thisIterator =>
4+
thisIterator: ({*} Iterator[T]) =>
55

66
def hasNext: Boolean
77
def next: T
8-
def map(f: {*} T => T): {f} Iterator[T] = new Iterator:
8+
def map(f: {*} T => T): {f, this} Iterator[T] = new Iterator:
99
def hasNext = thisIterator.hasNext
1010
def next = f(thisIterator.next)
1111
end Iterator
1212

1313
class C
1414
type Cap = {*} C
1515

16+
def map[T, U](it: {*} Iterator[T], f: {*} T => U): {it, f} Iterator[U] = new Iterator:
17+
def hasNext = it.hasNext
18+
def next = f(it.next)
19+
1620
def test(c: Cap, d: Cap, e: Cap) =
1721
val it = new Iterator[Int]:
1822
private var ctr = 0
@@ -21,3 +25,4 @@ def test(c: Cap, d: Cap, e: Cap) =
2125

2226
def f(x: Int): Int = if c == d then x else 10
2327
val it2 = it.map(f)
28+
val it3 = map(it, f)

0 commit comments

Comments
 (0)