无定型镜片的想法 [英] Shapeless lenses in idea

查看:87
本文介绍了无定型镜片的想法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试将2.0.0版的无矫正镜片用于scala 2.10.3 我有与此类似的代码:

I try to use shapless lenses of version 2.0.0 for scala 2.10.3 I have the code similar to this one:

import shapeless._
case class A(map: Map[String, String])
case class B(a: A)
val mapLens = lens[B] >> 'a >> 'map 

mapLens的推断类型是

AnyRef with Lens[B, Nothing] {val gen: LabelledGeneric.Aux[Nothing, ::[record.FieldType[Witness.Lt[Symbol]#T, Nothing], Nothing]]}

所以如果我想更改B实例的值

so if I want to change value of B instance

mapLens.set(b)(b.a.map + ("foo" -> "bar"))

我收到类型不匹配错误.该如何解决?

I get a type mismatch error. How to fix this?

P.S. 此处使用无定型镜片的例子. lens[Person].address.street如何工作?我的意思是编译器如何允许我们在lense类的实例上调用case类的方法?因为在LenseExamples对象中使用>>运算符

P.S. Here there is an example of using shapeless lenses. How does this lens[Person].address.street works? I mean how does compiler allow us to call methods of case class on instance of lense class? Because in LenseExamples object the >> operator is used

修改 已经在REPL中尝试过,并且可以正常工作.想法说了

edit Have tried in REPL and it works. Idea says that it

could not find implicit value for evidence parameter of type shapeless.LabelledGeneric[B]{type Repr = Out0}

同一个抱怨发出gra声

The same complain emits gradle

推荐答案

想法错误.您应该针对Scala插件报告一个错误.

Idea is wrong. You should report a bug against the Scala plugin.

这篇关于无定型镜片的想法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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