Skip to content

Instantly share code, notes, and snippets.

@clhodapp
Created April 21, 2018 04:27
Show Gist options
  • Save clhodapp/c9cf33d10869e021ef2e0ac7cee0b5f6 to your computer and use it in GitHub Desktop.
Save clhodapp/c9cf33d10869e021ef2e0ac7cee0b5f6 to your computer and use it in GitHub Desktop.
$ scala
Welcome to Scala 2.12.4 (OpenJDK 64-Bit Server VM, Java 1.8.0_121).
Type in expressions for evaluation. Or try :help.
scala> :paste
// Entering paste mode (ctrl-D to finish)
case class Setting[T](
key: String,
value: T
)
object ProjectExtra {
def inThisBuild(ss: Seq[Setting[_]]): Seq[Setting[_]] = ss
def inThisBuild[T](ts: T*)(implicit ev: T <:< Setting[_]): Seq[Setting[_]] = ts.map(ev.apply)
}
// Exiting paste mode, now interpreting.
defined class Setting
defined object ProjectExtra
scala> ProjectExtra.inThisBuild(List(Setting("foo", 3), Setting("bar", "bar")))
res0: Seq[Setting[_]] = List(Setting(foo,3), Setting(bar,bar))
scala> ProjectExtra.inThisBuild(Setting("foo", 3), Setting("bar", "bar"))
res1: Seq[Setting[_]] = ArrayBuffer(Setting(foo,3), Setting(bar,bar))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment