For anyone who is interested, here's a case study on serialization of scala closures that may or may not have been the result of a lengthy and passionate discussion about what you can and can't serialize and why it's necessary to generate a closure with a generating function if you want to use it in Spark
import java.io.{ByteArrayOutputStream, ObjectOutputStream, NotSerializableException}
object Temp {
def main(args: Array[String]): Unit = {
def serialize(value: Any): Array[Byte] = {