blackdrag commented on code in PR #3259:
URL: https://github.com/apache/groovy/pull/3259#discussion_r4509525415
##########
subprojects/groovy-ginq/src/main/groovy/org/apache/groovy/ginq/provider/collection/runtime/Queryable.java:
##########
@@ -516,6 +518,42 @@ default Queryable<T> union(Queryable<? extends T>
queryable) {
*/
List<T> toList();
+ /**
+ * Iterates the materialized elements. A static {@code for} loop calls this
+ * rather than wrapping the query as a single value.
+ *
+ * @return an iterator over the elements
+ * @since 7.0.0
+ */
+ default Iterator<T> iterator() {
+ return toList().iterator();
+ }
+
+ /**
+ * Coerces this query. Implementations that know the target type override
it.
+ *
+ * @param type the requested type
+ * @return the coerced value
+ * @since 7.0.0
+ */
+ default Object asType(Class<?> type) {
+ if (type == Queryable.class || List.class == type || Collection.class
== type || Iterable.class == type) {
+ return type == Queryable.class ? this : toList();
+ }
+ return this;
Review Comment:
if I do `def foo = queryable as Foo` then this code does not ensure `foo`
will be compatible with `Foo`. After the special casing is done you should
instead delegate to DGM or throw a GroovyCastException here.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]