Community
Participate
Working Groups
The problem is most easily explained with an example. Let's take the fold-Function: <T, R> fold(Iterable<T> iterable, R seed, (R,T)=>R function) When I write iterable.fold(anArrayList)[functionReturningList] the compiler complains that my function should return ArrayList instead. I.e. the seed wins when determining R. To get around this I have to explicitly cast anArrayList to List. This ruins an otherwise readable line of code. I worked around this by defining my own version of fold like so: <T, R, S extends R> fold(Iterable<T> iterable, S seed, (R,T)=>R function) However, the compiler should be able to correctly determine R without a third type variable.
Thanks for the report. I can reproduce the issue.
The following works now. val (List<String>,String)=>List<String> functionReturningList = [a, b| a += b return a ] #['foo'].fold(newArrayList, functionReturningList) added a test case.
This is still an issue with the more natural style strings.fold(newArrayList) [ list , b | list += b return list.sublist(1) ]