Last active
December 14, 2015 11:10
-
-
Save NIA/42a431a9e081ab35a6ca to your computer and use it in GitHub Desktop.
Scala hieroglyph experiments
This file contains hidden or 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
import language.{postfixOps,implicitConversions} | |
case class -->[A, B] (from: A, to: B) | |
implicit class ArrowSugar[A](private val self: A) { def --> [B] (other: B) = new -->(self, other)} | |
def diff(arrow: Int-->Int) = arrow match { | |
case x --> y => y - x | |
} | |
diff(1 --> 4) should be (3) | |
def buildMap[A,B](items: A-->B*) = items map {case (x --> y) => (x, y)} toMap | |
buildMap('2' --> "two", '5' --> "five") should be(Map(('2', "two"), ('5', "five"))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment