You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by GitBox <gi...@apache.org> on 2022/06/24 15:39:07 UTC

[GitHub] [groovy] eric-milles opened a new pull request, #1732: GROOVY-10223: support assignment/cast of `Optional` to array/collection

eric-milles opened a new pull request, #1732:
URL: https://github.com/apache/groovy/pull/1732

   Adds support for assignment of optional to arrays or collections -- and by extension an "iterator()" method and for-each iteration.  Does not support spread arguments (aka "def list = [*optional]" or "m(*optional)")
   ```groovy
   Object[] array = optional
   List<Object> list = optional
   Iterator<Object> optional.iterator()
   for (value in optional) { /*...*/ } // ... executed only if value is present
   ```
   
   https://issues.apache.org/jira/browse/GROOVY-10223


-- 
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: notifications-unsubscribe@groovy.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [groovy] eric-milles commented on pull request #1732: GROOVY-10223: support conversion of `Optional` to array/collection

Posted by GitBox <gi...@apache.org>.
eric-milles commented on PR #1732:
URL: https://github.com/apache/groovy/pull/1732#issuecomment-1165725099

   And this kind of thing is not supported without `getAt(int)` or `getAt(Integer)`:
   ```groovy
   def opt = Optional.of('')
   def (String x) = opt
   assert x == ''
   ```


-- 
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: notifications-unsubscribe@groovy.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [groovy] eric-milles commented on pull request #1732: GROOVY-10223: support conversion of `Optional` to array/collection

Posted by GitBox <gi...@apache.org>.
eric-milles commented on PR #1732:
URL: https://github.com/apache/groovy/pull/1732#issuecomment-1167664770

   @paulk-asert I agree, it seems the extension method `Optional<T> collect(Optional<S>,Closure<T>)` is not that valuable.  If deprecated, it would not resolve as an extension, which would then cause `List<T> collect(Object,Closure<T>)` to be selected instead.  I doubt any code that makes use of this is prepared for a list return value.


-- 
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: notifications-unsubscribe@groovy.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [groovy] eric-milles merged pull request #1732: GROOVY-10223: support conversion of `Optional` to array/collection

Posted by GitBox <gi...@apache.org>.
eric-milles merged PR #1732:
URL: https://github.com/apache/groovy/pull/1732


-- 
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: notifications-unsubscribe@groovy.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [groovy] eric-milles commented on pull request #1732: GROOVY-10223: support conversion of `Optional` to array/collection

Posted by GitBox <gi...@apache.org>.
eric-milles commented on PR #1732:
URL: https://github.com/apache/groovy/pull/1732#issuecomment-1165715088

   You can also do this, but I don't think it is an improvement over "optional.map(String::length).orElse(null)" or "optional.orElse(null)?.length()":
   ```groovy
   def nothing = Optional.empty(), something = Optional.of('foo')
   def value = nothing*.length()?[0]
   assert value == null
   value = something*.length()?[0]
   assert value == 3
   ```


-- 
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: notifications-unsubscribe@groovy.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [groovy] paulk-asert commented on pull request #1732: GROOVY-10223: support conversion of `Optional` to array/collection

Posted by GitBox <gi...@apache.org>.
paulk-asert commented on PR #1732:
URL: https://github.com/apache/groovy/pull/1732#issuecomment-1167957937

   > @paulk-asert I agree, it seems the extension method `Optional<T> collect(Optional<S>,Closure<T>)` is not that valuable. If deprecated, it would not resolve as an extension, which would then cause `List<T> collect(Object,Closure<T>)` to be selected instead. I doubt any code that makes use of this is prepared for a list return value.
   
   Yes, it would be a breaking change. We'd deprecate it now in Groovy 4 and remove in Groovy 5 with explanation in release notes. Folks wanting to prepare could potentially test with -Dgroovy.extension.disable=collect but that isn't very selective.
   We can explain the behavior either way, I just think the explanation is much simpler if it behaves like all the other fallback variants.


-- 
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: notifications-unsubscribe@groovy.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org