I did misunderstood your code. -> was a tuple; I read it as => (in which the syntax wouldn't even be valid). 

There are two issues with this code right now: 

1. You need to be careful here since the addInPlace shouldn't affect the data user passed in. In that case, you might need to do a foldByKey or use some initial zero value (with mapPartitions) to make sure you don't just reuse the first feature vector the user gave you. 

2. To improve performance, you'd want to remove the extra shuffle here (by not using reduceByKey/foldByKey and simply foldByKeyLocally - I don't think we have that in Spark; alternatively, you can just do mapPartitions and then collect everything to the driver to do the reduce).