Syntax understanding of scala function


override def generateJob(time: Time): Option[Job] = {
    parent.getOrCompute(time) match {
      case Some(rdd) =>
        val jobFunc = () => createRDDWithLocalProperties(time, displayInnerRDDOps) {
          foreachFunc(rdd, time)
        }
        Some(new Job(time, jobFunc))
      case None => None
    }
  }

val jobFunc = () => createRDDWithLocalProperties(time, displayInnerRDDOps) {
          foreachFunc(rdd, time)
        }
        
        createRDDWithLocalProperties 
        
Mar.01,2021

I don't know what other code looks like in your context, but if you're just trying to figure out what curly braces are for, here's an example:

val a = 1
val b = 2

val func = abstractAdd(a,b){
  addImpl
}

def abstractAdd(a: Int, b: Int)(tryDo: (Int, Int) => Int): Int = {
  tryDo(a, b)
}

def addImpl(a: Int, b: Int): Int = a + b

We have an operation abstractAdd that doesn't know how to add. In addition to passing in a and b to add, we also need to pass in a function that actually implements the addition. func implements the addition operation completely.

knowledge points involved: Coriarization , higher order functions


.  createRDDWithLocalProperties
createRDDWithLocalProperties(time, displayInnerRDDOps) {
          foreachFunc(rdd, time)
        }
        
Menu