I was trying to write a mkString function in Java8, a la Scala's useful mkString and ran into 2 issues that I could use some help on:
Is there a way to let the 'reduction' of the reduce() method of Stream be optional? I want to iterate over a list of Periods and join the periods that overlap and maintain both periods if they don't overlap:
I have the following example data set that I want to transform / reduce using Java stream api based on direction's value
The code is to return the lowest index in an array when the value in the array is the same as the index. If there are no matches i should return -1. For example:
I've got array of fruits:What I try to achieve is to reduce this array so it look like this:I've done this using very ugly for loop:
I have an array of objects, something like this:What needs to be accomplished is summing x from the array1 with x from the array2 that have the same index. Same goes for y and z. The final result should be a new array of objects containing the summed values.