10
9

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

ズンドコキヨシ with Scala

Last updated at Posted at 2016-03-11

元ネタ

Scalaらしく再帰とパターンマッチで。

kiyoshi.scala
import scala.util.Random
def zundoko(zd: List[String] = Nil): Unit = zd match {
  case "ドコ" :: "ズン" :: "ズン" :: "ズン" :: "ズン" :: _ => println(zd.reverse.mkString + "キ・ヨ・シ!")
  case _ => zundoko((if(Random.nextBoolean) "ズン" else "ドコ") :: zd)
}
zundoko()

再帰とパターンマッチ……先を越されてしまいましたorz

あ、あとYコンビネータで

kiYoshi.scala
import scala.util.Random
def Y[A, B](f: ((A => B), A) => B, x: A): B = f((y: A) => Y(f, y), x)
Y((zundoko: List[String] => Unit, zd: List[String]) => zd match {
  case "ドコ" :: "ズン" :: "ズン" :: "ズン" :: "ズン" :: _ => println(zd.reverse.mkString + "キ・ヨ・シ!")
  case _ => zundoko((if(Random.nextBoolean) "ズン" else "ドコ") :: zd)
}, Nil)

参考

10
9
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
10
9

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?