加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

scala – Cats中simolacrum中的@noop是什么

发布时间:2020-12-16 10:00:13 所属栏目:安全 来源:网络整理
导读:什么是猫的@noop注释.基本上,它不接受任何字符串别名,如@op.这是 scala doc /** * Annotation that may be applied to methods on a type that is annotated with `@typeclass`. * * Doing so results in the method being excluded from the generated synt
什么是猫的@noop注释.基本上,它不接受任何字符串别名,如@op.这是 scala doc

/**
 * Annotation that may be applied to methods on a type that is annotated with `@typeclass`.
 *
 * Doing so results in the method being excluded from the generated syntax ops type.
 */
class noop() extends StaticAnnotation

我对这个文档很困惑.有人可以向我解释并给我一个如何使用它的例子吗?

提前谢谢了

解决方法

所以假设你有这个类型类:

@typeclass trait Foo[A] {
     def bar(x: A)(y: A): A
}

然后你就可以(通过simulacrum定义的隐式语法)能够编写这个方法:

def baz[A: Foo](x: A,y: A): A = x bar y

如果你要用@noop注释bar方法,上面就不会编译说“bar不是A类的成员”,因为没有从A提供到有条形的东西的隐式转换方法.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读