Explanation of fold method of spark RDD

Well, it is actually pretty well explained by the official documentation: Aggregate the elements of each partition, and then the results for all the partitions, using a given associative and commutative function and a neutral “zero value”. The function op(t1, t2) is allowed to modify t1 and return it as its result value to avoid … Read more

Method Override with Scala 3 Macros

With new method Symbol.newClass (Scala 3.1.3) this becomes quite easy: import scala.annotation.experimental import scala.quoted.* object NewClass { inline def newClass[A]: A = ${newClassImpl[A]} @experimental def newClassImpl[A: Type](using Quotes): Expr[A] = { import quotes.reflect.* val name: String = TypeRepr.of[A].typeSymbol.name + “Impl” val parents = List(TypeTree.of[A]) def decls(cls: Symbol): List[Symbol] = List(Symbol.newMethod(cls, “func”, MethodType(List(“s”))(_ => List(TypeRepr.of[String]), _ … Read more

How to get ClassTag form TypeTag, or both at same time?

The library doesn’t provide a built-in method that directly converts a TypeTag to a ClassTag, but you can write one: import reflect.runtime.universe._ import reflect.ClassTag def typeToClassTag[T: TypeTag]: ClassTag[T] = { ClassTag[T]( typeTag[T].mirror.runtimeClass( typeTag[T].tpe ) ) } Then in your method just add before the implicit ClassTag is needed: implicit val c = typeToClassTag[T]