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 util.continuations._ | |
//scala-arm library http://github.com/jsuereth/scala-arm is needed | |
import resource._ | |
class SuspendableWrapper[A](t: Iterable[A]) { | |
def susp = new { | |
def foreach[B](f: A => B @suspendable): Unit @suspendable = { | |
val it = t.iterator | |
while(it.hasNext) { | |
f(it.next) |
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 java.io.StringReader | |
import scala.util.parsing.combinator._ | |
import scala.util.parsing.input._ | |
import scala.util.parsing.combinator.syntactical._ | |
import java.util.Properties | |
object JSONLikeProperties { | |
object Parser extends StandardTokenParsers { | |
lexical.delimiters ++= List("{", "}", "=") | |
//lexical.reserved ++= List("{", "}", "=") |
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 annotation.tailrec | |
import reflect.BeanInfo | |
import util.matching.Regex | |
import util.parsing.combinator.{Parsers, RegexParsers} | |
object RefactoredAkaraLogParser { | |
// イベントデータ | |
trait Event { | |
val event: String | |
} | |
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
class Foo { | |
import scala.collection.mutable.ArrayBuffer | |
val elements = List(1,2,3) | |
//ClassManifest is needed | |
def map[T:ClassManifest](block: Int => T) = { | |
val vals = ArrayBuffer[T]() | |
elements foreach{ i => vals += block(i) } | |
vals.toArray | |
} | |
} |
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
val seq: Seq[Int] = List(1, 2, 3) | |
println(seq eq seq.toList) // seq.toListはthisを返す(型だけが変わるので、同じインスタンス) |
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
trait DefaultValue[T] { | |
def value: T | |
} | |
object DefaultValue { | |
implicit object DefaultByteValue extends DefaultValue[Byte] { | |
def value: Byte = 0 | |
} | |
implicit object DefaultShortValue extends DefaultValue[Short] { | |
def value: Short = 0 | |
} |
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
trait Or[+A, +B] | |
case class LOr[+A, +B](a: A) extends Or[A, B] | |
case class ROr[+A, +B](b: B) extends Or[A, B] | |
implicit def lOr[A, B](implicit a: A): Or[A, B] = LOr[A, B](a) | |
implicit def rOr[A, B](implicit b: B): Or[A, B] = ROr[A, B](b) | |
def valueIsIntOrString[T](value: T)(implicit param: Or[T => String, T => Int]) = param match { | |
case LOr(t2String) => | |
println("value is String") |
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 OverloadingTest { | |
def f(x: Long) { println("Long!") } | |
def f(x: Double) { println("Double!") } | |
def main(args: Array[String]) { | |
f(1) | |
f(1L) | |
f(1.0) | |
f(1.0f) | |
} | |
} |
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 Args { | |
def main(args: Array[String]) { | |
args.foreach(println) | |
} | |
} |
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 ExecDir { | |
def main(args: Array[String]) { | |
val process = Runtime.getRuntime().exec("dir") | |
val in = process.getInputStream() | |
val it = Iterator.continually(in.read()) | |
println(it.takeWhile(_ != -1).map{_.toChar}.mkString) | |
} | |
} |