Scala 扩展双箭头 [英] Scala extends double arrow

查看:45
本文介绍了Scala 扩展双箭头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在查看 Anorm 源代码,对于 RowParser trait 它有声明:

I was looking at the Anorm source code and for the RowParser trait it has the declaration:

trait RowParser[+A] extends (Row => SqlResult[A]) { ... }

我很好奇 (Row => SqlResult[A]) 是什么类型?我在任何地方都找不到对语法的解释.

I was curious what type (Row => SqlResult[A]) is? I haven't been able to find an explanation of the syntax anywhere.

推荐答案

这是 Function1 的语法糖,与此相同:

This is syntactic sugar for Function1 which is the same as this:

trait RowParser[+A] extends Function1[Row, SqlResult[A]] 

如果您进一步查看 Anorm 源 你会看到当特性被实现时,它必须定义一个 apply 函数,因为它实现了 Function1 特性.

If you look further in the Anorm source you'll see that when the trait is implemented it has to define an apply function since it's implementing the Function1 trait.

这篇关于Scala 扩展双箭头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆