Skip to content

Instantly share code, notes, and snippets.

@iravid
Last active November 21, 2015 12:24
Show Gist options
  • Save iravid/85a08de6cc5c6c5082b9 to your computer and use it in GitHub Desktop.
Save iravid/85a08de6cc5c6c5082b9 to your computer and use it in GitHub Desktop.
package test
import scala.collection.immutable.StringOps
import scala.language.implicitConversions
object Main extends App {
val tags = Set(
Tag("bool", Set[Value[Value.T]](true, "hello", 156)),
Tag("int", 153),
Tag("string", "hello")
)
println(tags)
val values = List(
Value("156"),
Value(156),
Value(true)
)
println(values)
}
object Tag {
def apply(key: String, value: Long) = new Tag(key, Set(value))
def apply(key: String, value: Boolean) = new Tag(key, Set(value))
def apply(key: String, value: String) = new Tag(key, Set(value))
}
case class Tag(key: String, values: Set[Value[Value.T]])
object Value {
type T = X forSome { type X <: AnyVal }
implicit def number2Value(v: Long): Value[T] = LongValue(v)
implicit def string2Value(v: String): Value[T] = StringValue(v)
implicit def boolean2Value(v: Boolean): Value[T] = BooleanValue(v)
def apply(v: Long): Value[T] = LongValue(v)
def apply(v: String): Value[T] = StringValue(v)
def apply(v: Boolean): Value[T] = BooleanValue(v)
}
sealed trait Value[+T <: AnyVal] {
def v: T
}
case class StringValue(v: StringOps) extends Value[StringOps]
case class BooleanValue(v: Boolean) extends Value[Boolean]
case class LongValue(v: Long) extends Value[Long]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment