Scala公式ページの論文一覧のページのhtmlをパースして、自動でpdfのファイルっぽいものを全部ダウンロードするだけのものです
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
scala> def foo(a: => String){println("foo");println(a)} | |
foo: (a: => String)Unit | |
scala> def bar(b:Int):String = {println("bar "+b); ( b * 2 ).toString } | |
bar: (b: Int)String | |
scala> foo(bar(2)) | |
foo | |
bar 2 | |
4 |
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
scala> scala> implicit val yearOrdering = new Ordering[Language]{ | |
def compare(x: Language, y: Language) = x.year compare y.year | |
} | |
yearOrdering: java.lang.Object with Ordering[Language] = $anon$1@7910769b | |
scala> implicit val nameLengthOrdering = new Ordering[Language]{ | |
def compare(x: Language, y: Language) = x.name.length compare y.name.length | |
} | |
nameLengthOrdering: java.lang.Object with Ordering[Language] = $anon$1@38a3c5b6 |
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 def toGrepCallable(list:List[String]) = new { | |
def grep[A](regex:String)(func:String => A = identity _):List[A] = | |
list.collect{ | |
case s if regex.r.findFirstIn(s).isDefined => | |
func(s) | |
} | |
} |
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
scala> sealed abstract class A | |
case object B extends A | |
case object C extends A | |
def hoge(xs:Map[A,Int]){ xs foreach println } | |
val list = Map(B -> 1 ,C -> 2) | |
defined class A | |
defined module B |
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
def byteIteratorFromURL(url:String):Iterator[Byte] = { | |
val in = new java.net.URL(url).openStream | |
Iterator.continually(in.read).takeWhile(_ != -1).map(_.toByte) | |
} | |
def byteStreamFromURL(url:String):Stream[Byte] = { | |
val in = new java.net.URL(url).openStream | |
Stream.continually(in.read).takeWhile(_ != -1).map(_.toByte) | |
} |
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 Main{ | |
import scala.util.parsing.json.JSON | |
def gistsUrl(user:String) = "http://gist.github.com/api/v1/json/gists/" + user | |
def gistsFile(repo:String,fileName:String) = "https://raw.github.com/gist/" + repo + "/"+ fileName | |
type jsonType = Map[String,List[Map[String,Any]]] | |
def byteIteratorFromURL(url:String):Iterator[Byte] = { |
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
scala> DBObject("ccc" -> Map("aaa" -> "bbb")) | |
res54: com.mongodb.casbah.commons.Imports.DBObject = { "ccc" : [ [ "aaa" , "bbb"]]} | |
scala> DBObject("ccc" -> new java.util.HashMap[String,AnyRef](){put("aaa","bbb")}) | |
res55: com.mongodb.casbah.commons.Imports.DBObject = { "ccc" : { "aaa" : "bbb"}} |
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
// Scala実践プログラミング P177 http://amzn.to/nruUtV | |
printf("matched = %d%n",Stream.continually(readLine).takeWhile(null!=).zipWithIndex.collect{case(l,i)if l.matches("(.*%s.*)".format(args(0)))=>printf("%3d: %s%n",i+1,l)}.size) | |
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
scala> import com.mongodb.casbah.Imports._ | |
import com.mongodb.casbah.Imports._ | |
// MongoDBObjectつくる | |
scala> val obj = MongoDBObject("a" -> 1) | |
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder". | |
SLF4J: Defaulting to no-operation (NOP) logger implementation | |
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details. | |
obj: com.mongodb.casbah.commons.Imports.DBObject = { "a" : 1} |