Created
September 20, 2012 20:14
-
-
Save nirth/3758082 to your computer and use it in GitHub Desktop.
Scala Dojo September 2012
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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