pomadchin / template-macro

Scala macro to generate apply and unapply functions for an object
Apache License 2.0
0 stars 1 forks source link

Template macro

Build Status

The motivation is to avoid case class inheritance necessity. As the result it is possible to use macro, to generate apply and unapply function for an object.

Usage example

import annotations.template

case class SW(s: String)
case class IW(c: Int)
case class DW(d: Double)
case class PD(sw: SW, iw: IW, bw: DW)

@template((i: Int, s: String, d: Double) => PD(SW(s), IW(i), DW(d)))
object Test {
  println(apply(2, "sss", 2d))
  println(unapply(PD(SW("s"), IW(1100), DW(28d))))
}

Install

scalaVersion := "2.11.7"

resolvers ++= Seq(
  Resolver.sonatypeRepo("releases"),
  "DaunnC bintray repo" at "http://dl.bintray.com/daunnc/maven/"
)

addCompilerPlugin(
 "org.scalamacros" % "paradise" % "2.1.0-M5" cross CrossVersion.full
)

libraryDependencies += "com.dc" %% "template-macros" % "0.0.2"

License