Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#!/bin/env scala
trait 所有操作 {
protected type 操作符
protected def 创建操作符(操作: (Int, Int) => Int):操作符
final def = 创建操作符(_ + _)
final def = 创建操作符(_ * _)
}
implicit final class 整数(左值: Int) extends 所有操作 {
protected type 操作符 = Int => Int
protected final def 创建操作符(操作: (Int, Int) => Int) = { 右值 => 操作(左值, 右值) }
case class 一直(操作: (Int, Int) => Int) {
def (右值: Int) = {
(左值 to 右值).reduce(操作)
}
}
def (右值: Int) = 左值 to 右值
}
object 延后计算 extends 所有操作 {
protected type 操作符 = (Int, Int) => Int
protected final def 创建操作符(操作: (Int, Int) => Int) = 操作
}
import 延后计算._
println(110)
println(110)
println(110)
println(1 一直 加 到 10)
println(1 一直 乘 到 10)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.