Created
April 23, 2015 05:17
-
-
Save AndreasKostler/4ba9be00edfb52c4a67e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package au.com.cba.omnia.eventually.ops | |
import au.com.cba.omnia.eventually.schema.{Entity, EntityAware} | |
import SelectEntitySyntax._ | |
import com.twitter.scalding.typed.{ TypedPipe, Grouped } | |
import scala.reflect.ClassTag | |
trait GroupByEntity[C] { | |
type K | |
def op[E: EntityAware](p: TypedPipe[E]): Grouped[K,E] | |
} | |
trait LowPriorityGroupByEntity { | |
implicit val groupByEntityBare = { | |
new GroupByEntity[Nothing] { | |
type K = Entity | |
def op[E: EntityAware](p: TypedPipe[E]) = p.selectEntity[Entity].group | |
} | |
} | |
} | |
object GroupByEntity extends LowPriorityGroupByEntity { | |
@inline def apply[A](implicit groupByEntity: GroupByEntity[A]) = groupByEntity | |
implicit def groupBySelectedEntity[C <: Entity : ClassTag] = { | |
new GroupByEntity[C] { | |
type K = C | |
def op[E: EntityAware](p: TypedPipe[E]) = p.selectEntity[C].group | |
} | |
} | |
} | |
trait GroupByEntitySyntax { | |
implicit class GroupByEntityOps[E: EntityAware](pipe: TypedPipe[E]) { | |
def groupByEntity[C: GroupByEntity] = { | |
GroupByEntity[C].op[E](pipe) | |
} | |
} | |
} | |
object GroupByEntitySyntax extends GroupByEntitySyntax |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment