scala - HList filtered by foldRight is not providing instances -


i'm using librarydependencies += "com.chuusai" %% "shapeless" % "2.2.4"

currently have model hlist types like

sealed trait section case class header(...) extends section case class customer(...) extends section case class supplier(...) extends section case class tech(...) extends section type contractview = header :: (customer :: supplier :: hnil) :: tech :: hnil 

in user code, i'd filter technical sections not supposed view using foldright proposed in answer:

trait collectallrf extends poly2 {   implicit def atany[l <: hlist, x] = at[x, l](_ :: _) }  object collectvisrf extends collectallrf {   implicit def atinvis[l <: hlist, s <: section : invisiblesection] = at[s, l]((_, l) => l) } 

for example there defined:

trait invisiblesection[s <: section] implicit object _techisinvisible extends invisiblesection[tech] 

fold working correctly, not use following filter or map on object, example code:

val filtered = view.foldright(hnil)(collectvisrf) view.filter[header]  

produces compile error:

error: not find implicit value parameter partition: shapeless.ops.hlist.partition[shapeless.::[header,shapeless.::[shapeless.::[customer,shapeless.::[supplier,shapeless.hnil]],shapeless.hnil.type]],header]

while this

view.filter[header] 

and

val h = view.select[header]  val l = view.select[customer::supplier::hnil] val c = l.select[customer] val s = l.select[supplier] val manual = h :: (c :: s :: hnil) :: hnil manual.filter[header] 

compiles ok

lately i've found little hnil.type @ end of foldright's result type , changed filter definition to

view.foldright(hnil.asinstanceof[hnil])(collectvisrf) 

and worked properly

is expected behaviour, , if yes why there no

val hnil: hnil = hnil 

in library?

your eventual fix almost, not quite, right. rather asinstanceof should use type ascription,

view.foldright(hnil: hnil)(collectvisrf) 

your question why there no definition of hnil value typed hnil rather hnil.type one. shapeless different typical scala libraries in makes heavy use of singleton types, hnil.type included, current situation isn't wrong corresponding situation in scala standard library none.type , nil.type never desired.

nevertheless situation describe in question comes more like, it's real problem. think confusing have 2 hnil values, 1 more precise type other, question boils down to: how existing stuff break if hnil (the type) inferred type of hnil (the value) rather hnil.type now.

feel free open ticket in shapeless issue tracker on github investigate this, , if you'd give try, please :-)


Comments

Popular posts from this blog

javascript - Karma not able to start PhantomJS on Windows - Error: spawn UNKNOWN -

c# - Display ASPX Popup control in RowDeleteing Event (ASPX Gridview) -

Nuget pack csproj using nuspec -