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 scala.collection.JavaConversions._ | |
case class Foo(s: String) | |
val map: Map[Foo, String] = | |
Map( | |
Foo("a") -> "a", | |
Foo("b") -> "b") | |
val v = map.get("a") // should be a type error, actually returns null |
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
package demo | |
trait Bar | |
abstract class Foo[T] {} | |
object Foo { | |
implicit def FooFromBar[T <: Bar : Manifest]: Foo[T] = new Foo[T] { } | |
def apply[T : Foo] = implicitly[Foo[T]] | |
def baz[T : Foo](arg: T): Unit = { println("ha!")} |
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 sbt._ | |
class LiftProject(info: ProjectInfo) extends DefaultWebProject(info) { | |
val liftVersion = "2.3" | |
val liftWebkit = "net.liftweb" %% "lift-webkit" % liftVersion % "compile" | |
val liftMapper = "net.liftweb" %% "lift-mapper" % liftVersion % "compile" | |
val jetty = "org.mortbay.jetty" % "jetty" % "6.1.22" % "test" | |
val junit = "junit" % "junit" % "4.5" % "test" | |
val logback = "ch.qos.logback" % "logback-classic" % "0.9.26" |
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
object AuthenticatedSession extends Loggable { | |
def logIn(credentialsOption: Option[Credentials]): Twitter = { | |
val (tw, credentials) = credentialsOption match { | |
case Some(cr) => | |
(createTwitter(Some(cr)), cr) | |
case None => | |
val twitter = createTwitter(None) | |
val requestToken = twitter.getOAuthRequestToken | |
DesktopUtil.browse(requestToken.getAuthorizationURL) | |
(twitter, Dialog.showInput(null, "Enter the PIN from the Twitter authorization page in your browser", |
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
case class Word(word: String, count: Long) { | |
override def toString = word + ": " + count | |
def +(n: Long): Word = Word(word, count + n) | |
} | |
private def showWordCloud { | |
val words = statusTableModel.filteredStatuses.flatMap(_.text.split("\\s")) | |
val emptyMap = immutable.Map.empty[String, Word].withDefault(w => Word(w, 0)) | |
val counts = words.foldLeft(emptyMap)((map, word) => map(word) += 1) | |
val countList = counts.values.toList.sort(_.count > _.count) |
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
package scala { | |
trait Function23[-T1, -T2, -T3, -T4, -T5, -T6, -T7, -T8, -T9, -T10, -T11, -T12, -T13, -T14, -T15, -T16, -T17, -T18, -T19, -T20, -T21, -T22, -T23, +R] extends AnyRef { self => | |
def apply(v1:T1, v2:T2, v3:T3, v4:T4, v5:T5, v6:T6, v7:T7, v8:T8, v9:T9, v10:T10, v11:T11, v12:T12, v13:T13, v14:T14, v15:T15, v16:T16, v17:T17, v18:T18, v19:T19, v20:T20, v21:T21, v22:T22, v23:T23): R | |
override def toString() = "<function>" | |
def curry: T1 => T2 => T3 => T4 => T5 => T6 => T7 => T8 => T9 => T10 => T11 => T12 => T13 => T14 => T15 => T16 => T17 => T18 => T19 => T20 => T21 => T22 => T23 => R = { | |
(x1: T1) => ((x2: T2, x3: T3, x4: T4, x5: T5, x6: T6, x7: T7, x8: T8, x9: T9, x10: T10, x11: T11, x12: T12, x13: T13, x14: T14, x15: T15, x16: T16, x17: T17, x18: T18, x19: T19, x20: T20, x21: T21, x22: T22, x23: T23) => self.apply(x1,x2,x3,x4,x5,x6,x7,x8,x9,x10,x11,x12,x13,x14,x15,x16,x17,x18,x19,x20,x21,x22,x23)).curry | |
} | |
} | |
} |
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
implicit class RichString(s: String) extends RandomAccessSeq[Char] { | |
def apply(x: Int) = s.charAt(x); | |
// whatever | |
var foo = 3; | |
def twiddle = { foo += 1; foo } | |
} | |
yields | |