Examples:
5 :: "help" :: 8 :: "ldf" to create a list with type (Int, String)
"help" :: 8 :: "ldf" :: 9 to create a list with type (String, Int)
Here is what I got:
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
class MyA[A, B](val head: A, val tail: Option[MyA[B, A]]) { | |
override def toString() = head + tail.map( "," + _.toString).getOrElse("") | |
def ::( x: B) = new MyA(x, Some(this)) | |
} | |
object MyA { | |
def apply[A,B](value: A) : MyA[A, B] = new MyA(value, None) | |
} | |
// examples: | |
5 :: "help" :: 6 :: "kjl" :: 9 :: MyA("d") // 5,help,6,kjl,9,d | |
6:: "six" :: 7 :: "seven" :: 8 :: "eight" :: MyA(9) // 6,six,7,seven,8,eight,9 | |
6:: "six" :: 7 :: "seven" :: "eight" :: MyA(9) // does not compile |
-