Sparkathon - Developing Spark Structured Streaming Apps in Scala
- Multiple
groupByorgroupByKeyaggregations in a batch structured query
| import cats.Monad | |
| import cats.effect.IO | |
| import freestyle.tagless._ | |
| @tagless trait Logger { | |
| def debug(message: String): FS[Unit] | |
| } | |
| @tagless trait Summer { | |
| def sum(a: Int, b: Int): FS[Int] |
| import cats.data.State | |
| import freestyle.free._ | |
| /* domain objects */ | |
| sealed trait Acme | |
| object Acme { | |
| case object AcmeUK extends Acme | |
| case object AcmeUS extends Acme | |
| } |
| import cats.data.State | |
| import freestyle.tagless._ | |
| /* domain objects */ | |
| case class Id(id: String) | |
| case class AcmeItem(id: Id) | |
| /* state */ | |
| trait MapState[K, V] { | |
| type Type = Map[K, V] |
| import cats.data.State | |
| import freestyle.tagless._ | |
| /* domain objects */ | |
| case class Id(id: String) | |
| case class AcmeItem(id: Id) | |
| /* state */ | |
| trait MapState[K, V] { | |
| type Type = Map[K, V] |
| import cats.data.State | |
| import freestyle.free._ | |
| /* domain objects */ | |
| case class Id(id: String) | |
| case class AcmeItem(id: Id) | |
| /* state */ | |
| trait MapState[K, V] { |
| import cats.data.State | |
| import freestyle.free._ | |
| /* domain objects */ | |
| case class Id(id: String) | |
| case class AcmeItem(id: Id) | |
| /* state */ | |
| trait MapState[K, V] { |
| import cats.data.State | |
| import freestyle.tagless._ | |
| /* domain objects */ | |
| sealed trait Acme | |
| object Acme { | |
| case object AcmeUK extends Acme | |
| case object AcmeUS extends Acme | |
| } |
Sparkathon - Developing Spark Structured Streaming Apps in Scala
groupBy or groupByKey aggregations in a batch structured query| object workspace { | |
| implicit class DefinedValuesMapExtension[K >: Null, V](map: Map[K, Option[V]]) { | |
| def toDefinedValuesMap: Map[K, V] = map.collect { case (key, value) if value.isDefined => (key, value.get) } | |
| } | |
| val mapWithOptionalValues: Map[String, Option[Int]] = Map( | |
| "foo" -> Some(20), | |
| "bar" -> None, |
| object OneWayImplicits extends App { | |
| //outside implicits visible, but T is not visible inside | |
| case class Outwards[T](value: T) extends AnyVal | |
| //outside implicits invisible, T is visible inside | |
| case class Inwards[T](value: T) extends AnyVal | |
| implicit def outwardsFromT[T](implicit t: T): Outwards[T] = Outwards(t) | |
| implicit def tFromInwards[T](implicit inw: Inwards[T]): T = inw.value |