Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
下面的下划线是什么意思。这是 scalaz7 库的片段:
trait Apply[F[_]] extends Functor[F] { self => //... def ap[A, B](fa: => F[A])(f: => F[A => B]): F[B] //... def apF[A, B](f: => F[A => B]): F[A] => F[B] = ap(_)(f) // <----HERE //... }
使用它的一般规则是什么?
在 Scala 中,下划线通常是通配符。这里具体来说,它是参数名称的简写。所以 lambda 表达式ap(_)(f)等价于x => ap(x)(f).
ap(_)(f)
x => ap(x)(f)
_如果每个参数只使用一次,并且它们按照声明的顺序使用,则可以将其用作匿名函数的参数的简写。
_