2
我想學無形(2.3.2)。我已經創建了一個可擴展的記錄非常簡單的容器:無形可擴展記錄的API
case class Records[L <: HList](ps: L) {
def get(k: Witness)(implicit selector: Selector[L, k.T]): selector.Out = selector(ps)
def rm[V, Out <: HList](k: Witness)(implicit remover: Remover.Aux[L, k.T, (V, Out)]) =
this.copy(ps = remover(ps)._2)
def upd[F](f: F)(implicit updater: Updater[L, F]) = this.copy(ps = updater(ps, f))
}
現在我想實現像API方法:
def upsert[T](k: String, v: T) = ???
我所有的attemps都完成了像編譯錯誤:
could not find implicit value for parameter updater: shapeless.ops.record.Updater[L,T with shapeless.labelled.KeyTag[k.type,T]]
能否請你幫我瞭解如何建立這樣的API(未擰緊到不成形),以及如何收集信息以解決這些問題?
不知道是否會工作,但我認爲你應該更新型的同隱含參數添加到'upsert',因爲你已經使用'upd'完成。這是一個無形的一般經驗法則:如果它要求隱式值,請嘗試將其作爲隱式參數添加到相關函數中。 – Haspemulator
它的工作原理!謝謝 – hellraiser