public
Created

Scala Dojo September 2012

  • Download Gist
json_typesafe.scala
Scala
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
sealed trait JItem
type JMap = scala.collection.immutable.HashMap[String, JItem]
case class JInt(data: Int) extends JItem
case class JMapAsItem(val data: JMap) extends JItem
 
// ToDo: read about "implicit not found"
implicit def jmapAsItem2JMap(jmap:JMapAsItem):JMap = jmap.data
implicit def jmap2JMapAsItem(jmap:JMap):JMapAsItem = JMapAsItem(jmap)
implicit def int2JInt(i: Int): JInt = JInt(i)
implicit def jInt2Int(ji:JInt):Int = ji.data
 
val m:JMap = new JMap();
 
val m2:JMap = new JMap();
val m3:JMap = m2+("a" -> m)
val m4:JMap = m3 + ("b" -> 5)
println("hello world "+m4)
 
//val m5:JMap = m4 + ("c" -> "string")
/*
def sum(jmap: JMap) = {
jmap.values.foldRight(first, second)
}
*/

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.