2

我正在尝试创建自定义uPickleWritershapeless.HList转换为简单数组而不是复杂的嵌套对象。

但我无法提供足够的具体证据,我可以用我的poly

我有这个代码:

import upickle.Js
import upickle.default._
import shapeless._
import poly._
import shapeless.ops.hlist.{ToTraversable, Mapper}

object writeItem extends Poly1 {
  implicit def item[I](implicit w: Writer[I]) = at[I](w.write)(writer.write)
}

implicit def hListWriter[L <: HList, Mappr <:  Mapper[writeItem.type, L] ]
(implicit mapper: Mappr,
 trav: ToTraversable.Aux[Mappr#Out, List, Js.Value]) = Writer[L] {
  l => Js.Arr(l.map(writeItem).toList[Js.Value]:_*)
}

和编译错误:

找不到参数的隐式值toTraversableAux: shapeless.ops.hlist.ToTraversable.Aux[mapper.Out,List,upickle.Js.Value]

如何定义函数以通过转换HList为统一?Listmap

4

1 回答 1

1

我发现已经Mapper.Aux有这个目的了,结果方法定义如下:

  implicit def hListWriter[L <: HList, Out <: HList]
  (implicit mapper: Mapper.Aux[writeItem.type, L, Out],
   trav: ToTraversable.Aux[Out, List, Js.Value]) = Writer[L] {
    l => Js.Arr(l.map(writeItem).toList[Js.Value]:_*)
于 2015-07-22T07:56:25.953 回答