Skip to content

Instantly share code, notes, and snippets.

@nirth
Created September 20, 2012 20:14
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nirth/3758082 to your computer and use it in GitHub Desktop.
Save nirth/3758082 to your computer and use it in GitHub Desktop.
Scala Dojo September 2012
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)
}
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment