I was wondering if we can print the definition of a function in Scala. A function is treated as an object in Scala.
For example:
scala> val splitFunction = (value : String) => { value.split(" ")}
splitFunction: String => Array[String] = <function1>
Above, Scala interactive shell indicates that splitFunction has input parameter String and it returns Array of strings. What really function1 indicates here?
Is it possible to print or retrieve the definition of splitFunction?
We can achieve same in python: Is it possible to print a function as a string in Python?
Update: In Apache Spark, RDD lineage or DAG stores information about parent RDD and transformation at each stage. I am interested in fetching definition of a function (even lambda or anonymous functions) used as an argument to transformations such as flatMap or map.
For example: File - DebugTest.scala
val dataRDD = sc.textFile( "README.md" )
val splitFunction = (value : String) => {value.split(" ")}
val mapRDD = dataRDD.map(splitFunction )
println(mapRDD.toDebugString)
Output:
(1) MapPartitionsRDD[2] at map at DebugTest.scala:43 []
| README.md MapPartitionsRDD[1] at textFile at DebugTest.scala:41 []
| README.md HadoopRDD[0] at textFile at DebugTest.scala:41 []
From above output, I can understand what transformations are performed but cannot understand or retrieve definition for the splitFunction used as an argument in "map" transformation. Is there any way to retrieve or print it?