Created
August 6, 2009 11:33
-
-
Save liquidz/163263 to your computer and use it in GitHub Desktop.
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 ahoNum = Array( | |
"ぜ~ろ", "い~ち", "にぃ~", "さぁ~ん", | |
"よぉ~ん", "ごぉ~", "ろぉ~く", "ななぁ~", | |
"はぁ~ち", "きゅ~ぅ", "じゅ~ぅ" | |
) | |
class NabeInt(i:Int){ | |
def から(j:Int):List[Int] = (i to j).toList | |
} | |
class NabeIntList(ls:List[Int]){ | |
def まで数えて(f:Int => Boolean):NabeCond = { | |
new NabeCond(ls, List(f)) | |
} | |
} | |
class NabeCond(ls:List[Int], conditions:List[Int => Boolean]){ | |
def と(f:Int => Boolean):NabeCond = { | |
new NabeCond(ls, f :: conditions) | |
} | |
def の時だけ(f:Int => String):List[String] = { | |
var res:List[String] = List() | |
for(val i <- ls){ | |
var tmp:String = null | |
conditions.foreach(c => { | |
if(c(i)) tmp = f(i) | |
}) | |
res = (if(tmp == null) i.toString else tmp) :: res | |
} | |
res.reverse | |
} | |
} | |
class NabeStringList(ls:List[String]){ | |
def になります():Unit = ls.foreach(println) | |
} | |
implicit def int2nabeInt(i:Int) = { new NabeInt(i) } | |
implicit def list2nabeIntList(ls:List[Int]) = { new NabeIntList(ls) } | |
implicit def list2nabeStrList(ls:List[String]) = { new NabeStringList(ls) } | |
def 三の倍数(i:Int):Boolean = (i % 3) == 0 | |
def アホ(i:Int):String = ahoNum(i) | |
1 から 10 まで数えて 三の倍数 の時だけ アホ になります |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment