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
/* | |
jorge-ortizs-macbook-pro:tmp jeortiz$ cat Infix.scala | |
*/ | |
sealed abstract class LList[+T] | |
case object NNil extends LList[Nothing] | |
final case class :::[T](hd: T, tl: LList[T]) extends LList[T] | |
object Main extends Application { | |
val lst = "A" :: "B" :: Nil | |
val llst = "A" ::: "B" ::: NNil |
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
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 | |
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
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 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 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
W: Cannot find common ancestor between 52e7c125e20e287d000a0a41d216a1bdfc460808 and 06d39fc876d82d555e1320f4a437eb0320a9c95a. Ignoring merge info. | |
W:svn cherry-pick ignored (/network/branches/BR_X:92632-96171,96204-98991,99045-101079,101106-101795) - missing 431 commit(s) (eg 3005a390ddacc782eaec3beeacb68b1bb4e22513) | |
W:svn cherry-pick ignored (/network/branches/BR_Y:101976-102719,102756-102775) - missing 72 commit(s) (eg cafbe4cf1358feb01975e578d5a6626b294bb405) | |
W:svn cherry-pick ignored (/network/branches/BR_Z:102830-104448,104567-104934) - missing 79 commit(s) (eg cafbe4cf1358feb01975e578d5a6626b294bb405) | |
Found merge parent (svn:mergeinfo prop): 9397d0741b6c6e0beae912b2c7bb6ed25a4d7e2d | |
fatal: ambiguous argument 'aa27a1704498ca023516dea7526158f2d772bbe3^..06482d90eb5eb77254ceb6262759cf6b0e0a9d4b': unknown revision or path not in the working tree. | |
Use '--' to separate paths from revisions | |
rev-list aa27a1704498ca023516dea7526158f2d772bbe3^..06482d90eb5eb77254ceb6262759cf6b0e0a9d4b: command returned error: 128 |
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
scala> object Foo | |
defined module Foo | |
scala> val x = Foo | |
x: Foo.type = Foo$@24753433 | |
scala> val y = identity(Foo) | |
y: object Foo = Foo$@24753433 |
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 DynamicImpl(x: AnyRef) extends Dynamic { | |
def _select_(name: String): DynamicImpl = { | |
new DynamicImpl(x.getClass.getMethod(name).invoke(x)) | |
} | |
def _invoke_(name: String)(args: Any*) = { | |
new DynamicImpl(x.getClass.getMethod(name, args.map(_.asInstanceOf[AnyRef].getClass) : _*).invoke(x, args.map(_.asInstanceOf[AnyRef]) : _*)) | |
} | |
override def typed[T] = x.asInstanceOf[T] | |
override def toString = "Dynamic(" + x.toString + ")" | |
} |
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
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 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
// The way Scala for-comprehensions work is that: | |
for (x <- c) f(x) | |
// simply translates to: | |
c.foreach(x => f(x)) | |
// Likewise: |
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
// Usage: | |
// p(instance)('privateMethod)(arg1, arg2, arg3) | |
class PrivateMethodCaller(x: AnyRef, methodName: String) { | |
def apply(_args: Any*): Any = { | |
val args = _args.map(_.asInstanceOf[AnyRef]) | |
def _parents: Stream[Class[_]] = Stream(x.getClass) #::: _parents.map(_.getSuperclass) | |
val parents = _parents.takeWhile(_ != null).toList | |
val methods = parents.flatMap(_.getDeclaredMethods) | |
val method = methods.find(_.getName == methodName).getOrElse(throw new IllegalArgumentException("Method " + methodName + " not found")) |
OlderNewer