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 Memoized[T,R] { | |
| import scala.collection.mutable._ | |
| private[this] val cache = new HashMap[T,R] | |
| def cacheOrApply( t:T )( f: => R ):R = cache get(t) getOrElse{ | |
| val rv = f | |
| cache += t -> rv | |
| rv | |
| } | |
| } |
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 Memorized[T,R] { | |
| import scala.collection.mutable._ | |
| val cache = new HashMap[T,R] | |
| def cacheOrApply( t:T )( f: => R ):R = cache get(t) getOrElse{ | |
| val rv = f | |
| cache += t -> rv | |
| println("do %s:%s" format(t, rv)) | |
| rv | |
| } |
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 AAMaker { | |
| import util.Random | |
| val rnd = new Random | |
| def asSeq[T](xs:Seq[Product]) = xs.map{_.productIterator.toSeq.asInstanceOf[Seq[T]]} | |
| def choice[T](xs:Seq[T]):T = xs(rnd.nextInt(xs.size)) | |
| val rinkaku = asSeq[String](Seq(("(", ")"), ("(", ")"), ("|", "|"), ("|", "|"))) | |
| var otete = asSeq[String](Seq(("", "", "", "", ""), ("", "", "m", "", ""), ("", "", "ლ", "", ""), ("ლ", "", "", "ლ", ""), ("", "「", "", "", "「"), ("", " つ", "", "", "つ"), ("", " ", "", "", "o彡゚"), ("", "n", "", "", "η"), ("", "∩", "", "∩", ""), ("∩", "", "", "", "∩"), ("ヽ", "", "", "", "ノ"), ("┐", "", "", "", "┌"), ("╮", "", "", "", "╭"), ("<", "", "", "", "/"), ("╰", "", "", " ", ""), ("o", "", "", "", "o"), ("o", "", "", "", "ツ"), ("", "", "", "", "ノシ"))) | |
| val omeme = asSeq[String](Seq(("\u25d5", "\u25d5"), ("╹", "╹"), (">", "<"), ("^", "^"), ("・", "・"), ("´・", "・`"), ("`・", "・´"), ("´", "`"), ("≧", "≦"), ("゚", "゚"), ("\"", "\""), ("・ิ", "・ิ"), ("❛", "❛"), ("⊙", "⊙"), (" ̄", " ̄"), ("◕ˇ", "ˇ◕"))) | |
| var okuti = Seq("ω", "∀", |
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.io.{Codec, Source} | |
| import scala.util.matching.Regex | |
| import java.io._ | |
| import java.net.URL | |
| object HtmlScraper { | |
| def getSource(url: String ) = { | |
| val in = new URL(url).openStream |
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> implicit def d2s(d:Date) = {println("d2s"); d.toString} | |
| d2s: (d: java.util.Date)java.lang.String | |
| scala> def foo[T](d:T)(implicit f:(T =>String) ) = {println(f.toString);f(d) } | |
| foo: [T](d: T)(implicit f: (T) => String)String | |
| scala> foo( new Date) | |
| <function1> | |
| d2s | |
| res2: String = Wed Sep 15 16:10:46 JST 2010 |
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.io.{Codec, Source} | |
| import scala.util.matching.Regex | |
| import java.io._ | |
| import java.net.URL | |
| trait ScrapedHtml { | |
| val src:Iterable[String] | |
| def write( fileName:String ):Unit = { | |
| import scala.util.control.Exception._ |
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.io.{Codec, Source} | |
| import java.io._ | |
| import java.net.URL | |
| import scala.collection.{Iterable, IterableLike} | |
| trait ScrapedHtml extends Iterable[String] with IterableLike[String, ScrapedHtml]{ | |
| val src:Iterable[String] | |
| import scala.collection.generic.CanBuildFrom |
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
| hogehoge |
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 java.util.{Map => JMap, HashMap => JHashMap} | |
| import java.util.{Map=>JMap, HashMap=>JHashMap} | |
| scala> import java.io.Serializable | |
| import java.io.Serializable | |
| scala> type SerializableMap[A,B] = JMap[A,B] with Serializable | |
| defined type alias SerializableMap | |
| scala> def process[A,B]( key:A,value:B,m:SerializableMap[A,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
| // import ModelImplicitly._ | |
| // modelOf[AbstractReadOnlyModel].as{"foo"} | |
| object ModelImplicitly{ | |
| trait ModelBuilder[A[X] <: IModel[X]] { | |
| def as[B](f: => B): A[B] | |
| } | |
| implicit object AbstractReadOnlyModelBuilder extends | |
| ModelBuilder[AbstractReadOnlyModel]{ |