Fun with method names

2 views
Skip to first unread message

Zach Cox

unread,
Jan 27, 2011, 3:05:45 PM1/27/11
to Iowa Scala Enthusiasts
Luke & I had some fun on Twitter yesterday:

http://twitter.com/#!/rubbish/status/30297799820054528

object I {
def ♥(s: String) { println("I ♥ " + s) }
def `<3`(s: String) { println("I <3 " + s) }
}

I ♥ "Iowa Scala Enthusiasts"
I `<3` "Iowa Scala Enthusiasts"

A fun little tidbit is that this is actually part of how Scala
provides Map element literals using the -> and → operators, like
Map("a" -> 1):

http://www.scala-lang.org/api/current/scala/Predef$$ArrowAssoc.html
https://lampsvn.epfl.ch/trac/scala/browser/scala/tags/R_2_8_1_final/src//library/scala/Predef.scala#L170

Those operators are not built-in to the language. Predef has an
implicit that can wrap anything in an ArrowAssoc instance, and then
its -> and → methods return a Tuple2[A, B] which can be inserted into
a Map[A, B]. You could just as easily define a new one to support
Map("a" ♥ 1). Scalable language FTW.

Tony Bibbs

unread,
Jan 27, 2011, 3:47:06 PM1/27/11
to iowa-scala-...@googlegroups.com
Nerds.

Of course, with this group, it's a term of endearment.
--
Tony Bibbs
Phone: 515.259.0003
Twitter, Skype, Facebook: tonybibbs
Web: http://www.tonybibbs.com

Reply all
Reply to author
Forward
0 new messages