default implementation for Iterator.cancelIteration (does nothing) and not implemented errors for iterator methods (better error messages)

This commit is contained in:
Sergey Chernov 2025-08-13 23:34:54 +03:00
parent 48a7f0839c
commit f45310f7d9

View File

@ -17,5 +17,26 @@
package net.sergeych.lyng.obj
val ObjIterator by lazy { ObjClass("Iterator") }
/**
* Iterator should provide lyng-level iterator functions:
*
* - hasNext()
* - next()
* - optional cancelIteration() that _may_ be called when iteration is performed
* only on the part of the iterable entity. Implement it when there are resources
* to be reclaimed on iteration interruption.
*/
val ObjIterator by lazy {
ObjClass("Iterator").apply {
addFn("cancelIteration", true) {
ObjVoid
}
addFn("hasNext", true) {
raiseNotImplemented("hasNext() is not implemented")
}
addFn("next", true) {
raiseNotImplemented("next() is not implemented")
}
}
}