Skip to content

Instantly share code, notes, and snippets.

@NIA
Last active December 14, 2015 11:10
Show Gist options
  • Save NIA/42a431a9e081ab35a6ca to your computer and use it in GitHub Desktop.
Save NIA/42a431a9e081ab35a6ca to your computer and use it in GitHub Desktop.
Scala hieroglyph experiments
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