title: Why are aggregate and fold two different APIs in Spark?
body: <p>When using the Scala standard lib, I can do somthing like this:</p>
  
  <pre><code>scala&gt; val scalaList = List(1,2,3)
  scalaList: List[Int] = List(1, 2, 3)
  
  scala&gt; scalaList.foldLeft(0)((acc,n)=&gt;acc+n)
  res0: Int = 6
  </code></pre>
  
  <p>Making one Int out of many Ints.</p>
  
  <p>And I can do something like this:</p>
  
  <pre><code>scala&gt; scalaList.foldLeft("")((acc,n)=&gt;acc+n.toString)
  res1: String = 123
  </code></pre>
  
  <p>Making one String out of many Ints.</p>
  
  <p>So, foldLeft could be either homogeneous or heterogeneous, whichever we want, it's in one API.</p>
  
  <p>While in Spark, if I want one Int out of many Ints, I can do this:</p>
  
  <pre><code>scala&gt; val rdd = sc.parallelize(List(1,2,3))
  rdd: org.apache.spark.rdd.RDD[Int] = ParallelCollectionRDD[1] at parallelize at &lt;console&gt;:12
  scala&gt; rdd.fold(0)((acc,n)=&gt;acc+n)
  res1: Int = 6
  </code></pre>
  
  <p>The fold API is similar to foldLeft, but it is only homogeneous, a RDD[Int] can only produce Int with fold.</p>
  
  <p>There is a aggregate API in spark too:</p>
  
  <pre><code>scala&gt; rdd.aggregate("")((acc,n)=&gt;acc+n.toString, (s1,s2)=&gt;s1+s2)
  res11: String = 132
  </code></pre>
  
  <p>It is heterogeneous, a RDD[Int] can produce a String now.</p>
  
  <p>So, why are fold and aggregate implemented as two different APIs in Spark? </p>
  
  <p>Why are they not designed like foldLeft that could be both homogeneous and heterogeneous?</p>
  
  <p>(I am very new to Spark, please excuse me if this is a silly question.)</p>