[ 
https://issues.apache.org/jira/browse/GROOVY-10223?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17559303#comment-17559303
 ] 

ASF GitHub Bot commented on GROOVY-10223:
-----------------------------------------

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.




> Add support for Optional to DefaultTypeTransformation.asCollection()
> --------------------------------------------------------------------
>
>                 Key: GROOVY-10223
>                 URL: https://issues.apache.org/jira/browse/GROOVY-10223
>             Project: Groovy
>          Issue Type: Improvement
>          Components: groovy-jdk
>            Reporter: Stephen Smith
>            Assignee: Eric Milles
>            Priority: Trivial
>              Labels: features
>
> The JDK recently added support for *Optional::stream()* which returns a 
> stream containing either the unwrapped value or an empty stream if the 
> *Optional* is empty.
> In the groovy-jdk, using iteration however will call
> {noformat}
> DefaultTypeTransformation.asCollection(){noformat}
> which does not specifically check for type *Optional*, instead it will just 
> wrap the *Optional* itself in a *List* rather than the unwrapped value as the 
> default behavior.
> Adding an _if else_ clause will allow using the Optional as either a single 
> or empty list.
> {code:java}
> if (value instanceOf Optional) {
>    return ((Optional)value).map(List::of).orElse(List.of())
> }{code}
>  Alternatively, add an *asList()* to the Optional class.
>  (edit: 2021-09-13, missing bracket in code example)
>  



--
This message was sent by Atlassian Jira
(v8.20.7#820007)

Reply via email to