Skip to content

Instantly share code, notes, and snippets.

@chidakiyo
Last active August 29, 2015 14:13
Show Gist options
  • Save chidakiyo/cd16c4509b8989e5f196 to your computer and use it in GitHub Desktop.
Save chidakiyo/cd16c4509b8989e5f196 to your computer and use it in GitHub Desktop.
硬貨における強制通用力の上限(社内研修)
object LegalTender extends App {
val yenCoins = List(1, 5, 10, 50, 100, 500)
implicit val yenMax = 20 // デフォルト値定義してるのでコレをコメントアウトしても動く
implicit class Coin(x: Int) {
def rcptMax(implicit max: Int = 20) = { x * max }
}
val sumCoins = (coins: List[Int]) => Option(coins map (_ rcptMax) sum)
sumCoins(yenCoins).foreach(println) // 13320
}
@yukinagae
Copy link

🐯

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment